1
1
const config = require ( '../configs' ) ;
2
2
const GoogleStrategy = require ( 'passport-google-oauth20' ) . Strategy ;
3
3
const { AppError } = require ( '../libraries/error-handling/AppError' ) ;
4
- const { getByGoogleId, create, updateById } = require ( '../domains/user/service' ) ;
4
+ const {
5
+ getByGoogleId,
6
+ create,
7
+ updateById,
8
+ } = require ( '../domains/user/service' ) ;
5
9
6
10
const getGoogleStrategy = ( ) => {
7
- console . log ( 'config' , config ) ;
8
11
return new GoogleStrategy (
9
12
{
10
13
clientID : config . GOOGLE_CLIENT_ID ,
11
14
clientSecret : config . GOOGLE_CLIENT_SECRET ,
12
15
callbackURL : `${ config . HOST } /api/auth/google/callback` ,
13
- scope : [ 'profile' , 'email' ]
16
+ scope : [ 'profile' , 'email' ] ,
14
17
} ,
15
18
async ( accessToken , refreshToken , profile , cb ) => {
16
19
try {
17
- const trimmedPayloadForSession = await getOrCreateUserFromGoogleProfile ( {
18
- profile,
19
- accessToken,
20
- } ) ;
20
+ const trimmedPayloadForSession = await getOrCreateUserFromGoogleProfile (
21
+ {
22
+ profile,
23
+ accessToken,
24
+ }
25
+ ) ;
21
26
cb ( null , trimmedPayloadForSession ) ;
22
27
} catch ( error ) {
23
28
cb ( error , null ) ;
@@ -28,12 +33,12 @@ const getGoogleStrategy = () => {
28
33
29
34
async function getOrCreateUserFromGoogleProfile ( { profile, accessToken } ) {
30
35
const isAdmin = config . ADMIN_USERNAMES . includes ( profile . emails [ 0 ] . value ) ;
31
-
36
+
32
37
const payload = {
33
38
email : profile . emails [ 0 ] . value ,
34
39
displayName : profile . displayName ,
35
40
authType : 'google' ,
36
-
41
+
37
42
google : {
38
43
id : profile . id ,
39
44
email : profile . emails [ 0 ] . value ,
0 commit comments