feathers
feathers copied to clipboard
OAuth account linking
I'm implementing OAuth account linking, which is described here https://docs.feathersjs.com/api/authentication/oauth.html#account-linking
I have the issue with exception case when OAuth profile is already connected to some other user account. When looking at the following line https://github.com/feathersjs/feathers/blob/v4.5.11/packages/authentication-oauth/src/strategy.ts#L152 the flow will always result in finding existing user with given profile. What I want is to detect that case and inform user that given profile is already connected to some other user account and not the one currently logged in.
My idea was to handle that in OAuth strategy:
async findEntity(profile, params) { const { authentication } = params; const entity = super.findEntity(profile, params); // when param authentication is present that means profile connect // profile can be connected only if no entity found for it if (authentication && entity) { throw new Conflict('Profile already connected'); } return entity; } }
That works but now in the frontend authentication-client is not picking reported error and the url stays as /dashboard#error=Profile%20already%20connected
. I have a call to reAuthenticate
but error is not picked because user is authenticated.
Is there a way for authentication client picks OAuth error when user is already signed in?
Thank you