Skip to content

Google OAuth with existing user throws Validation Error #3231

Answered by n-bravo
n-bravo asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @daffl ,

I managed to solve this issue by patching the googleId of the existing user in a beforeHook of the authentication service.

The hook looks likes this:

const authenticationHooks = {
  before: {
    create: [async (context) => {
      if (context.data.strategy === 'google' && context.data.id_token) {
        const data = (await context.app.service('users').find({query: {
          email: context.data.id_token.payload.email,
          googleId: null
        }, $limit: 1, $select: ['id']})).data;
        if (data.length > 0) {
          const userId = data[0].id;
          await context.app.service('users').patch(userId, {googleId: context.data.id_token.payload.sub});
        }
…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@n-bravo
Comment options

Answer selected by n-bravo
@daffl
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants