https://supertokens.com/ logo
Title
p

productdevbook

12/14/2022, 6:55 AM
https://supertokens.com/docs/thirdpartyemailpassword/common-customizations/deduplication/implementing-deduplication
ts
     thirdPartySignInUpPOST: async (input) => {
              try {
                await originalImplementation.thirdPartySignInUpPOST!(input)
              }
              catch (err: any) {
                if (err.message === 'Cannot sign up as email already exists') {
                  // this error was thrown from our function override above.
                  // so we send a useful message to the user
                  return {
                    status: 'GENERAL_ERROR',
                    message: 'Seems like you already have an account with another method. Please use that instead.',
                  }
                }
                throw err
              }
r

rp

12/14/2022, 6:56 AM
hey @productdevbook it seems to be an issue with how you may have configured the github provider.
@sattvikc can help here
s

sattvikc

12/14/2022, 6:58 AM
just a min, taking a look
can i see your github init ?
p

productdevbook

12/14/2022, 7:00 AM
ts

   recipeList: [
      ThirdPartyEmailPassword.init({
        providers: [
          Github({
            clientId: env.github.appId,
            clientSecret: env.github.privateKey,
          }),
        ],
but login client and supertoken token etc coming
s

sattvikc

12/14/2022, 7:03 AM
is the privateKey same as clientSecret provided by github ?
p

productdevbook

12/14/2022, 7:04 AM
yes
but dont used
How can I login even though it gives an error?
s

sattvikc

12/14/2022, 7:05 AM
can you check if the env is set correctly ?
p

productdevbook

12/14/2022, 7:06 AM
yes same code
s

sattvikc

12/14/2022, 7:06 AM
it worked earlier?
p

productdevbook

12/14/2022, 7:07 AM
It still works, I'm officially logging in, but that error always comes
s

sattvikc

12/14/2022, 7:09 AM
the 401 error typically means the token was not acquired on the token API. could you replicate that request on the postman ?
p

productdevbook

12/14/2022, 7:09 AM
Against the error, your system registers the user and the token is returned. interested
s

sattvikc

12/14/2022, 7:10 AM
strange! just to be sure, which error are you referring to ?
if the user API does not pass, the user will not be added to the core
p

productdevbook

12/14/2022, 7:12 AM
no your system added
all delete db and reset github user
and after login same
and return token your system and login client
super token db
this error backend code.
s

sattvikc

12/14/2022, 7:15 AM
do u mean the backend has an issue with the API call and still the login works as expected?
p

productdevbook

12/14/2022, 7:15 AM
yes
s

sattvikc

12/14/2022, 7:15 AM
is the returned email correct as well?
p

productdevbook

12/14/2022, 7:15 AM
yes
s

sattvikc

12/14/2022, 7:16 AM
could you share your complete supertokens init? maybe I can try to reproduce and see
p

productdevbook

12/14/2022, 7:16 AM
my backend code
s

sattvikc

12/14/2022, 7:16 AM
let me know your frontend and backend SDK versions as well
p

productdevbook

12/14/2022, 7:17 AM
"supertokens-web-js": "^0.3.0", "supertokens-node": "^12.1.2",
s

sattvikc

12/14/2022, 7:17 AM
okay, let me get back to u in a while
p

productdevbook

12/14/2022, 7:17 AM
await originalImplementation.thirdPartySignInUpPOST!(input)
iam delete and fixed https://supertokens.com/docs/thirdpartyemailpassword/common-customizations/deduplication/implementing-deduplication but your added
s

sattvikc

12/14/2022, 7:20 AM
not sure I understand that correctly, what did you delete?
p

productdevbook

12/14/2022, 7:22 AM
I get an error when I add the code
r

rp

12/14/2022, 7:22 AM
You can't delete
await originalImplementation.thirdPartySignInUpPOST!(input)
. if that's not there, then it won't actually attempt to login the user at all.
ok so the problem is that you are calling
await originalImplementation.thirdPartySignInUpPOST!(input)
twice..
that will, obviously, not work
p

productdevbook

12/14/2022, 7:23 AM
According to your docs I have added those codes but it is causing the error
r

rp

12/14/2022, 7:23 AM
If you see in our docs, we call
await originalImplementation.thirdPartySignInUpPOST
just once in the override
but you are calling it twice.
So the second time is failing.
which is expected
This is the code in the file you sent above:
thirdPartySignInUpPOST: async (input) => {
              try {
                await originalImplementation.thirdPartySignInUpPOST!(input)

                if (!originalImplementation.thirdPartySignInUpPOST)
                  throw new Error('thirdPartySignInUpPOST is not available')

                const response = await originalImplementation.thirdPartySignInUpPOST(input)

                if (response.status === 'OK') {
                  const externalUserId = response.user.thirdParty
                    ? `${response.user.thirdParty.id}|${response.user.thirdParty.userId}`
                    : null

                  await storage.userRepo.ensureUserExists({
                    superTokensUserId: response.user.id,
                    email: response.user.email,
                    externalAuthUserId: externalUserId || undefined,
                  })
                }

                return response
              }
And as you can see, you are calling
await originalImplementation.thirdPartySignInUpPOST!(input)
at the start of the funciton, and then
const response = await originalImplementation.thirdPartySignInUpPOST(input)
again.
So your override code is just wrong.
p

productdevbook

12/14/2022, 7:24 AM
ts

   try {
                const response = await originalImplementation.thirdPartySignInUpPOST!(input)

                if (!originalImplementation.thirdPartySignInUpPOST)
                  throw new Error('thirdPartySignInUpPOST is not available')

                if (response.status === 'OK') {
                  const externalUserId = response.user.thirdParty
                    ? `${response.user.thirdParty.id}|${response.user.thirdParty.userId}`
                    : null

                  await storage.userRepo.ensureUserExists({
                    superTokensUserId: response.user.id,
                    email: response.user.email,
                    externalAuthUserId: externalUserId || undefined,
                  })
                }

                return response
              }
thats true ?
r

rp

12/14/2022, 7:24 AM
whats before the
try
line?
p

productdevbook

12/14/2022, 7:25 AM
ts

      thirdPartySignInUpPOST: async (input) => {
              try {
                const response = await originalImplementation.thirdPartySignInUpPOST!(input)

                if (!originalImplementation.thirdPartySignInUpPOST)
                  throw new Error('thirdPartySignInUpPOST is not available')

                if (response.status === 'OK') {
                  const externalUserId = response.user.thirdParty
                    ? `${response.user.thirdParty.id}|${response.user.thirdParty.userId}`
                    : null

                  await storage.userRepo.ensureUserExists({
                    superTokensUserId: response.user.id,
                    email: response.user.email,
                    externalAuthUserId: externalUserId || undefined,
                  })
                }

                return response
              }
              catch (err: any) {
                if (err.message === 'Cannot sign up as email already exists') {
                  // this error was thrown from our function override above.
                  // so we send a useful message to the user
                  return {
                    status: 'GENERAL_ERROR',
                    message: 'Seems like you already have an account with another method. Please use that instead.',
                  }
                }
                throw err
              }
            },
r

rp

12/14/2022, 7:25 AM
yea. this seems fine
if this also doens't work, then please check your github credentials,.
p

productdevbook

12/14/2022, 7:26 AM
okay thank you now fixed
and email signup return error 🔥
r

rp

12/14/2022, 7:26 AM
nice
p

productdevbook

12/14/2022, 7:27 AM
I am working on a project of mine. I will sponsor you once I go live and start making money.
Thanks for all the help