Add google things on the front
This commit is contained in:
@@ -51,9 +51,9 @@ export class AuthController {
|
||||
@Get("logged/google")
|
||||
@UseGuards(AuthGuard('google'))
|
||||
async googleLoginCallbakc(@Req() req: any) {
|
||||
let user = await this.usersService.user({googleID: req.id});
|
||||
let user = await this.usersService.user({googleID: req.user.googleID});
|
||||
if (!user) {
|
||||
user = await this.usersService.createUser(req)
|
||||
user = await this.usersService.createUser(req.user)
|
||||
await this.settingsService.createUserSetting(user.id);
|
||||
}
|
||||
return this.authService.login(user);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { Strategy, VerifyCallback } from 'passport-google-oauth20';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { User } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class GoogleStrategy extends PassportStrategy(Strategy) {
|
||||
@@ -8,7 +9,7 @@ export class GoogleStrategy extends PassportStrategy(Strategy) {
|
||||
super({
|
||||
clientID: process.env.GOOGLE_CLIENT_ID,
|
||||
clientSecret: process.env.GOOGLE_SECRET,
|
||||
callbackURL: 'http://localhost:3000/google/redirect',
|
||||
callbackURL: process.env.GOOGLE_CALLBACK_URL,
|
||||
scope: ['email', 'profile'],
|
||||
});
|
||||
}
|
||||
@@ -19,16 +20,16 @@ export class GoogleStrategy extends PassportStrategy(Strategy) {
|
||||
profile: any,
|
||||
done: VerifyCallback,
|
||||
): Promise<any> {
|
||||
console.log(profile);
|
||||
const { name, emails, photos, username } = profile;
|
||||
const user = {
|
||||
email: emails[0].value,
|
||||
username,
|
||||
email: profile.emails[0].value,
|
||||
username: profile.displayName,
|
||||
password: null,
|
||||
googleID: profile.id,
|
||||
// firstName: name.givenName,
|
||||
// lastName: name.familyName,
|
||||
// picture: photos[0].value,
|
||||
};
|
||||
done(null, user);
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user