Skip to content

Commit

Permalink
fix issues suggested by coderabbit
Browse files Browse the repository at this point in the history
  • Loading branch information
AmruthPillai committed Jan 13, 2025
1 parent 33cb3db commit 227870a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
4 changes: 4 additions & 0 deletions apps/server/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ export class AuthService {
}

if (
this.configService.get("OPENID_AUTHORIZATION_URL") &&
this.configService.get("OPENID_ISSUER") &&
this.configService.get("OPENID_TOKEN_URL") &&
this.configService.get("OPENID_USER_INFO_URL") &&
this.configService.get("OPENID_CLIENT_ID") &&
this.configService.get("OPENID_CLIENT_SECRET") &&
this.configService.get("OPENID_CALLBACK_URL")
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/auth/strategy/github.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export class GitHubStrategy extends PassportStrategy(Strategy, "github") {
if (!email) throw new BadRequestException(ErrorMessage.InvalidCredentials);

try {
const user =
user =
(await this.userService.findOneByIdentifier(email)) ??
(username && (await this.userService.findOneByIdentifier(username)));
(username ? await this.userService.findOneByIdentifier(username) : null);

if (!user) throw new Error(ErrorMessage.InvalidCredentials);
if (!user) throw new BadRequestException(ErrorMessage.InvalidCredentials);

done(null, user);
} catch {
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/auth/strategy/google.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export class GoogleStrategy extends PassportStrategy(Strategy, "google") {
if (!email) throw new BadRequestException(ErrorMessage.InvalidCredentials);

try {
const user =
user =
(await this.userService.findOneByIdentifier(email)) ??
(username && (await this.userService.findOneByIdentifier(username)));
(username ? await this.userService.findOneByIdentifier(username) : null);

if (!user) throw new Error(ErrorMessage.InvalidCredentials);
if (!user) throw new BadRequestException(ErrorMessage.InvalidCredentials);

done(null, user);
} catch {
Expand Down
8 changes: 4 additions & 4 deletions apps/server/src/auth/strategy/openid.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ export class OpenIDStrategy extends PassportStrategy(Strategy, "openid") {
) {
const { displayName, emails, photos, username } = profile;

const email = emails?.[0].value ?? `${username}@github.com`;
const email = emails?.[0].value ?? `${username}@openid.com`;
const picture = photos?.[0].value;

let user: User | null = null;

if (!email) throw new BadRequestException(ErrorMessage.InvalidCredentials);

try {
const user =
user =
(await this.userService.findOneByIdentifier(email)) ??
(username && (await this.userService.findOneByIdentifier(username)));
(username ? await this.userService.findOneByIdentifier(username) : null);

if (!user) throw new Error(ErrorMessage.InvalidCredentials);
if (!user) throw new BadRequestException(ErrorMessage.InvalidCredentials);

done(null, user);
} catch {
Expand Down

0 comments on commit 227870a

Please sign in to comment.