Skip to content

Commit

Permalink
[Server] 클라이언트와 api 연동 작업 (login, socket history) (#209)
Browse files Browse the repository at this point in the history
* feat: socket 빈 히스토리면 [] 보내기

* feat: 로그인시 유저 닉네임도 같이 보내주기
  • Loading branch information
yangdongsuk authored Dec 7, 2023
1 parent 5c2f20a commit 462fe15
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 7 additions & 1 deletion server/src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,18 @@ describe('AuthService', () => {
email: '[email protected]',
provider: ProviderType.APPLE,
};
const existUser = { email: user.email, userId: 1 } as UserModel;
const existUser = {
email: user.email,
userId: 1,
nickname: 'test',
} as UserModel;
jest
.spyOn(authService, 'authenticateWithEmailAndProvider')
.mockResolvedValue(existUser);
jest.spyOn(authService, 'loginUser').mockReturnValue({
accessToken: 'access_token',
refreshToken: 'refresh_token',
nickname: 'test',
});

const result = await authService.loginWithEmailAndProvider(user);
Expand Down Expand Up @@ -252,6 +257,7 @@ describe('AuthService', () => {
jest.spyOn(authService, 'loginUser').mockReturnValue({
accessToken: 'access_token',
refreshToken: 'refresh_token',
nickname: 'NewUser',
});

const result = await authService.registerUser(user);
Expand Down
8 changes: 6 additions & 2 deletions server/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,15 @@ export class AuthService {
* @returns {{accessToken: string, refreshToken: string}}
*/

loginUser(user: UserModel): { accessToken: string; refreshToken: string } {
loginUser(user: UserModel): {
accessToken: string;
refreshToken: string;
nickname: string;
} {
const accessToken = this.signToken(user, 'access');
const refreshToken = this.signToken(user, 'refresh');

return { accessToken, refreshToken };
return { accessToken, refreshToken, nickname: user.nickname };
}

/**
Expand Down
4 changes: 1 addition & 3 deletions server/src/shared-checklists/shared-checklists.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,7 @@ export class SharedChecklistsGateway
const historyArray = history.map((item) => JSON.parse(item));
const flattenedArray = historyArray.flat();

if (history.length > 0) {
this.sendToClient(client, 'history', flattenedArray);
}
this.sendToClient(client, 'history', flattenedArray);
}

/**
Expand Down

0 comments on commit 462fe15

Please sign in to comment.