@@ -27,11 +27,67 @@ export const AuthenticationOptions: AuthOptions = {
2727 clientId : process . env . GOOGLE_ID ,
2828 clientSecret : process . env . GOOGLE_SECRET ,
2929 allowDangerousEmailAccountLinking : true ,
30+ profile : async ( profile ) => {
31+ logger . debug ( "Google profile:" , profile ) ;
32+
33+ const existingUser = await (
34+ await cachedDb
35+ ) . findObject ( CollectionId . Users , { email : profile . email } ) ;
36+ if ( existingUser ) {
37+ existingUser . id = profile . sub ;
38+ return existingUser ;
39+ }
40+
41+ const user = new User (
42+ profile . name ,
43+ profile . email ,
44+ profile . picture ,
45+ false ,
46+ await GenerateSlug ( await cachedDb , CollectionId . Users , profile . name ) ,
47+ [ ] ,
48+ [ ] ,
49+ ) ;
50+
51+ user . id = profile . sub ;
52+
53+ return user ;
54+ } ,
3055 } ) ,
3156 SlackProvider ( {
3257 clientId : process . env . NEXT_PUBLIC_SLACK_CLIENT_ID as string ,
3358 clientSecret : process . env . SLACK_CLIENT_SECRET as string ,
3459 allowDangerousEmailAccountLinking : true ,
60+ profile : async ( profile ) => {
61+ logger . debug ( "Slack profile:" , profile ) ;
62+
63+ const existing = await (
64+ await cachedDb
65+ ) . findObject ( CollectionId . Users , { email : profile . email } ) ;
66+
67+ if ( existing ) {
68+ existing . slackId = profile . sub ;
69+ existing . id = profile . sub ;
70+ console . log ( "Found existing user:" , existing ) ;
71+ return existing ;
72+ }
73+
74+ const user = new User (
75+ profile . name ,
76+ profile . email ,
77+ profile . picture ,
78+ false ,
79+ await GenerateSlug ( await cachedDb , CollectionId . Users , profile . name ) ,
80+ [ ] ,
81+ [ ] ,
82+ profile . sub ,
83+ 10 ,
84+ 1 ,
85+ ) ;
86+
87+ user . id = profile . sub ;
88+
89+ return user ;
90+ } ,
3591 } ) ,
3692 Email ( {
3793 server : {
0 commit comments