Skip to content

Commit

Permalink
fix(server): oauth linking error message
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasm91 committed Jun 13, 2024
1 parent 8c2195c commit e8be70d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions server/src/services/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,12 @@ describe('AuthService', () => {
userMock.getAdmin.mockResolvedValue(userStub.user1);
userMock.create.mockResolvedValue(userStub.user1);

await expect(sut.callback({ url: 'http://immich/auth/login?code=abc123' }, loginDetails)).resolves.toEqual(
loginResponseStub.user1oauth,
await expect(sut.callback({ url: 'http://immich/auth/login?code=abc123' }, loginDetails)).rejects.toThrow(
BadRequestException,
);

expect(userMock.update).not.toHaveBeenCalled();
expect(userMock.create).toHaveBeenCalled();
expect(userMock.create).not.toHaveBeenCalled();
});

it('should allow auto registering by default', async () => {
Expand Down
8 changes: 6 additions & 2 deletions server/src/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,12 @@ export class AuthService {
// link existing user
if (!user) {
const emailUser = await this.userRepository.getByEmail(profile.email);
if (emailUser && !emailUser.oauthId) {
user = await this.userRepository.update(emailUser.id, { oauthId: profile.sub });
if (emailUser) {
if (emailUser.oauthId) {
throw new BadRequestException('User already exists, but is linked to another account.');
} else {
user = await this.userRepository.update(emailUser.id, { oauthId: profile.sub });
}
}
}

Expand Down

0 comments on commit e8be70d

Please sign in to comment.