chore: added types to createProviderAccount ,ethod in auth.service file
This commit is contained in:
@@ -224,7 +224,10 @@ export class AuthService {
|
|||||||
statusCode: HttpStatus.NOT_FOUND,
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check to see if entry for magic-link is present in the Account table for this user
|
/**
|
||||||
|
* * Check to see if entry for Magic-Link is present in the Account table for user
|
||||||
|
* * If user was created with another provider findUserByEmail may return true
|
||||||
|
*/
|
||||||
const profile = {
|
const profile = {
|
||||||
provider: 'email',
|
provider: 'email',
|
||||||
id: user.value.email,
|
id: user.value.email,
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ export class GithubStrategy extends PassportStrategy(Strategy) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async validate(accessToken, refreshToken, profile, done) {
|
async validate(accessToken, refreshToken, profile, done) {
|
||||||
console.dir(profile);
|
|
||||||
const user = await this.usersService.findUserByEmail(
|
const user = await this.usersService.findUserByEmail(
|
||||||
profile.emails[0].value,
|
profile.emails[0].value,
|
||||||
);
|
);
|
||||||
@@ -34,7 +33,10 @@ export class GithubStrategy extends PassportStrategy(Strategy) {
|
|||||||
return createdUser;
|
return createdUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to see if entry for github is present in the Account table for this user
|
/**
|
||||||
|
* * 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
|
||||||
|
*/
|
||||||
const providerAccountExists =
|
const providerAccountExists =
|
||||||
await this.authService.checkIfProviderAccountExists(user.value, profile);
|
await this.authService.checkIfProviderAccountExists(user.value, profile);
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,10 @@ export class GoogleStrategy extends PassportStrategy(Strategy) {
|
|||||||
return createdUser;
|
return createdUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to see if entry for google is present in the Account table for this user
|
/**
|
||||||
|
* * 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
|
||||||
|
*/
|
||||||
const providerAccountExists =
|
const providerAccountExists =
|
||||||
await this.authService.checkIfProviderAccountExists(user.value, profile);
|
await this.authService.checkIfProviderAccountExists(user.value, profile);
|
||||||
|
|
||||||
|
|||||||
@@ -40,27 +40,10 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
|||||||
if (!payload) throw new ForbiddenException(INVALID_ACCESS_TOKEN);
|
if (!payload) throw new ForbiddenException(INVALID_ACCESS_TOKEN);
|
||||||
|
|
||||||
const user = await this.usersService.findUserById(payload.sub);
|
const user = await this.usersService.findUserById(payload.sub);
|
||||||
|
|
||||||
if (O.isNone(user)) {
|
if (O.isNone(user)) {
|
||||||
throw new UnauthorizedException(USER_NOT_FOUND);
|
throw new UnauthorizedException(USER_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
const profile = {
|
|
||||||
provider: 'email',
|
|
||||||
id: user.value.email,
|
|
||||||
};
|
|
||||||
|
|
||||||
const providerAccountExists =
|
|
||||||
await this.authService.checkIfProviderAccountExists(user.value, profile);
|
|
||||||
|
|
||||||
if (!providerAccountExists)
|
|
||||||
await this.usersService.createProviderAccount(
|
|
||||||
user.value,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
profile,
|
|
||||||
);
|
|
||||||
|
|
||||||
return user.value;
|
return user.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,10 @@ export class MicrosoftStrategy extends PassportStrategy(Strategy) {
|
|||||||
return createdUser;
|
return createdUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to see if entry for microsoft is present in the Account table for this user
|
/**
|
||||||
|
* * 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
|
||||||
|
*/
|
||||||
const providerAccountExists =
|
const providerAccountExists =
|
||||||
await this.authService.checkIfProviderAccountExists(user.value, profile);
|
await this.authService.checkIfProviderAccountExists(user.value, profile);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { PrismaService } from 'src/prisma/prisma.service';
|
import { PrismaService } from 'src/prisma/prisma.service';
|
||||||
import * as O from 'fp-ts/Option';
|
import * as O from 'fp-ts/Option';
|
||||||
import { AuthUser, SSOProviderProfile } from 'src/types/AuthUser';
|
import { AuthUser } from 'src/types/AuthUser';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserService {
|
export class UserService {
|
||||||
@@ -69,7 +69,12 @@ export class UserService {
|
|||||||
return createdUser;
|
return createdUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createProviderAccount(user, accessToken, refreshToken, profile) {
|
async createProviderAccount(
|
||||||
|
user: AuthUser,
|
||||||
|
accessToken: string,
|
||||||
|
refreshToken: string,
|
||||||
|
profile,
|
||||||
|
) {
|
||||||
const createdProvider = await this.prisma.account.create({
|
const createdProvider = await this.prisma.account.create({
|
||||||
data: {
|
data: {
|
||||||
provider: profile.provider,
|
provider: profile.provider,
|
||||||
|
|||||||
Reference in New Issue
Block a user