Hello, i'm having an infinite loop while logging i...
# support-questions
e
Hello, i'm having an infinite loop while logging in with
emailPasswordSignIn
can't figure out why
n
Hi, Can you give a little more context? Is any API being called in a loop?
e
Copy code
js
              emailPasswordSignIn: async (input) => {
                //TODO: add device-token logic

                const validEmail = await validateEmail(input.email)

                if (!validEmail) {
                  return {
                    status: 'WRONG_CREDENTIALS_ERROR',
                  }
                }

                //check if user is in db

                const hasuraUser = await sdk.getUserByEmail({
                  email: input.email.toLowerCase().trim(),
                })

                if (hasuraUser.data?.customer.length === 0) {
                  return {
                    status: 'WRONG_CREDENTIALS_ERROR',
                  }
                }

                //check if there is a superTokensUser
                const superTokensUser = await ThirdPartyEmailPassword.getUsersByEmail(input.email)

                if (!superTokensUser) {
                  //check if password is valid and create superTokensUser

                  const valid = await bcrypt.compare(
                    input.password,
                    hasuraUser.data.customer[0].password,
                  )

                  if (!valid) {
                    return {
                      status: 'WRONG_CREDENTIALS_ERROR',
                    }
                  }

                  const signupResponse = await ThirdPartyEmailPassword.emailPasswordSignUp(
                    input.email,
                    input.password,
                  )

                  if (signupResponse.status !== 'OK') {
                    return {
                      status: 'WRONG_CREDENTIALS_ERROR',
                    }
                  }
                }

                return ThirdPartyEmailPassword.emailPasswordSignIn(input.email, input.password)
              },
return ThirdPartyEmailPassword.emailPasswordSignIn(input.email, input.password)
not sure if i need to await, but doesnt work either
added console.log after last line 😉
before*
n
Right, can you post the full config you pass to SuperTokens init?
e
Copy code
js
export const backendConfig = (): TypeInput => {
  return {
    framework: 'express',
    supertokens: {
      // These are the connection details of the app you created on supertokens.com
      connectionURI: process.env.SUPERTOKENS_CONNECTION_URI,
      apiKey: process.env.SUPERTOKENS_API_KEY,
    },
    appInfo,
    recipeList: [
      ThirdPartyEmailPassword.init({
        providers: [
          Google({
            clientId: process.env.GOOGLE_CLIENT_ID,
            clientSecret: process.env.GOOGLE_CLIENT_SECRET,
          }),
        ],
Copy code
js
export const appInfo = {
  // learn more about this on https://supertokens.com/docs/emailpassword/appinfo
  appName: 'Lokalist Webshop',
  apiDomain: process.env.NEXT_PUBLIC_FRONTEND_URL,
  websiteDomain: process.env.NEXT_PUBLIC_FRONTEND_URL,
  apiBasePath: '/api/auth',
  websiteBasePath: '/auth',
}
n
@EdwinN1337 in the object where you create your overridden
emailPasswordSignIn
function, the parent function should receive an object (named
original
in the docs). When returning you should use
original.emailPasswordSignIn
instead of
ThirdPartyEmailPassword.emailPasswordSignIn
In the snippet you posted, you are calling the same function. When you override any of the functions,
ThirdPartyEmailPassword.function
now points to your function. So returning
ThirdPartyEmailPassword.emailPasswordSignIn
is just calling itself endlessly
e
wow
makes sence
oops thanks for the fast support hehe
n
Happy to help
e
return oI.emailPasswordSignIn(input)
😉
n
Yep!
e
Might not get it, what's the difference between
Copy code
js
               //check if there is a superTokensUser
                const superTokensUser = await ThirdPartyEmailPassword.getUsersByEmail(input.email)
vs using the
original
n
So the SDK has its own implementations of these functions. The idea is that when you override them there are two versions of each function (yours and the SDKs). Overriding a function means that using
ThirdParyEmailPassword.function
would call your version of the function (defaulting to the SDKs version if you dont override it).
original.function
always calls the SDKs implementation and not yours
Ideally to avoid issues in the future, inside any overrides you should always use
original
unless you intentionally want to call your version of a function
Think about it this way, when a user is signing in if you want to do some logic and then let the SDK continue normally you would override and then 1. Do your logic 2. Call original to let the SDK continue If you want to take over completely 1. Do your logic 2. Return your values and so on
Does that help?
e
ahh yeah clear!
absolutely
do you know if there is any capacitor implementation with supertokens
n
So our SDKs should work with Capacitor as well
Have you run into any specific issues while trying to implement it?
e
will try now, just finished the fetch/web implementation
if we use the native
import { Http, HttpOptions, HttpResponse } from '@capacitor-community/http'
we need our own interceptor?
n
Ah right, yes you would need your own
We dont have one for native http
e
not sure if it would work with fetch (see issue)
but i'll try
n
You can refer to the SDKs logic and build it though, shouldnt be that complicated of a translation
3 Views