chore: user displayName and photoURL property updates itself when found with SSO providers

This commit is contained in:
Balu Babu
2023-01-23 05:31:03 +05:30
parent 96ed2f2119
commit b2acd5511c
4 changed files with 53 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import { Injectable, UnauthorizedException } from '@nestjs/common';
import { AuthService } from '../auth.service';
import { UserService } from 'src/user/user.service';
import * as O from 'fp-ts/Option';
import * as E from 'fp-ts/Either';
@Injectable()
export class GithubStrategy extends PassportStrategy(Strategy) {
@@ -33,6 +34,16 @@ export class GithubStrategy extends PassportStrategy(Strategy) {
return createdUser;
}
if (!user.value.displayName || !user.value.photoURL) {
const updatedUser = await this.usersService.updateUserDetails(
user.value,
profile,
);
if (E.isLeft(updatedUser)) {
throw new UnauthorizedException(updatedUser.left);
}
}
/**
* * Check to see if entry for Github is present in the Account table for user
* * If user was created with another provider findUserByEmail may return true

View File

@@ -1,9 +1,10 @@
import { Strategy, VerifyCallback } from 'passport-google-oauth20';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable } from '@nestjs/common';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { UserService } from 'src/user/user.service';
import * as O from 'fp-ts/Option';
import { AuthService } from '../auth.service';
import * as E from 'fp-ts/Either';
@Injectable()
export class GoogleStrategy extends PassportStrategy(Strategy) {
@@ -33,6 +34,16 @@ export class GoogleStrategy extends PassportStrategy(Strategy) {
return createdUser;
}
if (!user.value.displayName || !user.value.photoURL) {
const updatedUser = await this.usersService.updateUserDetails(
user.value,
profile,
);
if (E.isLeft(updatedUser)) {
throw new UnauthorizedException(updatedUser.left);
}
}
/**
* * Check to see if entry for Google is present in the Account table for user
* * If user was created with another provider findUserByEmail may return true

View File

@@ -4,6 +4,7 @@ import { Injectable, UnauthorizedException } from '@nestjs/common';
import { AuthService } from '../auth.service';
import { UserService } from 'src/user/user.service';
import * as O from 'fp-ts/Option';
import * as E from 'fp-ts/Either';
@Injectable()
export class MicrosoftStrategy extends PassportStrategy(Strategy) {
@@ -33,6 +34,16 @@ export class MicrosoftStrategy extends PassportStrategy(Strategy) {
return createdUser;
}
if (!user.value.displayName || !user.value.photoURL) {
const updatedUser = await this.usersService.updateUserDetails(
user.value,
profile,
);
if (E.isLeft(updatedUser)) {
throw new UnauthorizedException(updatedUser.left);
}
}
/**
* * Check to see if entry for Microsoft is present in the Account table for user
* * If user was created with another provider findUserByEmail may return true