@@ -159,45 +159,43 @@ exports.onExecutePostLogin = async (event, api) => {
159159 return api . access . deny ( "Please contact support or the IAM team. (err=link-lookup)" ) ;
160160 }
161161
162- try {
163- // Ignore non-verified users
164- let userAccountList = candidateUserAccountList . filter (
165- ( u ) => u . email_verified
166- ) ;
162+ // Ignore non-verified users
163+ let userAccountList = candidateUserAccountList . filter (
164+ ( u ) => u . email_verified
165+ ) ;
167166
168- if ( userAccountList . length <= 1 ) {
169- // The user logged in with an identity which is the only one Auth0 knows about
170- // or no data returned
171- // Do not perform any account linking
172- return ;
173- }
167+ if ( userAccountList . length <= 1 ) {
168+ // The user logged in with an identity which is the only one Auth0 knows about
169+ // or no data returned
170+ // Do not perform any account linking
171+ return ;
172+ }
174173
175- if ( userAccountList . length === 2 ) {
176- // Auth0 is aware of 2 identities with the same email address which means
177- // that the user just logged in with a new identity that hasn't been linked
178- // into the other existing identity. Here we pass the other account to the
179- // linking function
180-
181- await linkAccount (
182- api ,
183- mgmtClient ,
184- event . user ,
185- userAccountList . filter ( ( u ) => u . user_id !== event . user . user_id ) [ 0 ]
174+ if ( userAccountList . length === 2 ) {
175+ const candidateUserId = userAccountList . filter (
176+ ( u ) => u . user_id !== event . user . user_id
177+ ) [ 0 ] ;
178+ try {
179+ return await linkAccount ( api , mgmtClient , event . user , candidateUserId ) ;
180+ } catch ( err ) {
181+ console . error (
182+ `Could not link ${ event . user . user_id } with ${ candidateUserId } `
186183 ) ;
187- } else {
188- // data.length is > 2 which, post November 2020 when all identities were
189- // force linked manually, shouldn't be possible
190- var error_message =
191- `Error linking account ${ event . user . user_id } as there are ` +
192- `over 2 identities with the email address ${ event . user . email } ` +
193- userAccountList . map ( ( x ) => x . user_id ) . join ( ) ;
194- console . error ( error_message ) ;
195- throw new Error ( error_message ) ;
184+ return api . access . deny ( "Please contact support or the IAM team. (err=link-link)" ) ;
196185 }
197- } catch ( err ) {
198- console . error ( "An error occurred while linking accounts:" , err ) ;
199- return api . access . deny ( err . message || String ( err ) ) ;
200186 }
201187
202- return ;
188+ // Auth0 is aware of 2 identities with the same email address which means
189+ // that the user just logged in with a new identity that hasn't been linked
190+ // into the other existing identity. Here we pass the other account to the
191+ // linking function
192+
193+ // data.length is > 2 which, post November 2020 when all identities were
194+ // force linked manually, shouldn't be possible
195+ var error_message =
196+ `Error linking account ${ event . user . user_id } as there are ` +
197+ `over 2 identities with the email address ${ event . user . email } ` +
198+ userAccountList . map ( ( x ) => x . user_id ) . join ( ) ;
199+ console . error ( error_message ) ;
200+ return api . access . deny ( error_message ) ;
203201} ;
0 commit comments