Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions backend/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ export class AuthController {
@Res() res: Response,
) {
const profile = req.user;
const email = profile?.emails?.[0]?.value;
const email = profile?.emails?.find((entry) => entry.verified)?.value;
if (!email) {
throw new BadRequestException(
'Google profile did not contain an email address',
'Google account has no verified email address',
);
}

Expand Down Expand Up @@ -271,21 +271,21 @@ export class AuthController {
@Res() res: Response,
) {
const profile = req.user;
const githubId = profile?.id?.toString();
const email = profile?.emails?.[0]?.value;
const identifier = email || (githubId ? `github:${githubId}` : null);
if (!identifier) {
throw new BadRequestException('GitHub profile could not be identified');
const email = profile?.emails?.find((entry) => entry.verified)?.value;
if (!email) {
throw new BadRequestException(
'GitHub account has no verified email address',
);
}

const fullName =
this.buildFullName([
profile?.displayName,
profile?.username,
]) || identifier;
]) || email;

const tokens = await this.authService.handleOAuthLogin(
identifier,
email,
fullName,
this.getSessionContext(req),
);
Expand Down
2 changes: 2 additions & 0 deletions backend/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';

import { AuthService } from './auth.service';
import { AuthController } from './auth.controller';
import { TokenRevocationService } from './token-revocation.service';
import { TwoFactorService } from './two-factor.service';
import { RefreshSession } from './entities/refresh-session.entity';
import { UsersModule } from '../users/users.module';
Expand Down Expand Up @@ -33,6 +34,7 @@ import { GithubStrategy } from './strategies/github.strategy';
controllers: [AuthController],
providers: [
AuthService,
TokenRevocationService,
TwoFactorService,
JwtStrategy,
GoogleStrategy,
Expand Down
Loading
Loading