https://supertokens.com/ logo
Url clone error
s

sdekna

04/09/2023, 6:18 AM
I am using
supertokens-web-js
sdk with sveltekit... it is working properly, however, after a user successfully signs in, I am getting this error:
500 url.clone is not a function
My init function:
js
export function init_supertoken_auth() {
  try {
    SuperTokens.init({
      appInfo: {
        apiDomain: "....",
        apiBasePath: "/",
        appName: "....",
      },
      recipeList: [
        Session.init(),
        ThirdPartyEmailPassword.init(),
      ],
      enableDebugLogs: true,
    });
  } catch (error) {
    console.log({ error })
  }
}
And my sign in function looks like this:
js
export async function sign_in_handler(event) {
  try {
    const raw_form_data = new FormData(event.target);
    const email = raw_form_data.get('email') as string;
    const password = raw_form_data.get('password') as string;

    const response = await emailPasswordSignIn({
      formFields: [
        {
          id: 'email',
          value: email
        },
        {
          id: 'password',
          value: password
        }
      ],
    });
    if (response.status === 'FIELD_ERROR') {
      response.formFields.forEach((formField) => {
        if (formField.id === 'email') {
          // Email validation failed (for example incorrect email syntax).
          console.log(formField.error)
        }
      });
    } else if (response.status === 'WRONG_CREDENTIALS_ERROR') {
      console.log('Email password combination is incorrect.')
    } else {
      // sign in successful. The session tokens are automatically handled by
      // the frontend SDK.
      console.log('sign in success')
      await post_sign_in_flow()
    }
  } catch (error: any) {
    if (error.isSuperTokensGeneralError === true) {
      // this may be a custom error message sent from the API by you.
      console.log(error.message)
    } else {
      console.log(error)
    }
  }
}
How do I prevent the url clone? the sign in works and session is initiated properly.
r

rp

04/09/2023, 6:30 AM
Hey @sdekna
Does that error happen after emailPasswordSignIn returns?
s

sdekna

04/09/2023, 6:31 AM
yes, after it returns with a successful reply... if I put wrong credintials it just gives me a wrong credintials error, no url.clone error
r

rp

04/09/2023, 6:33 AM
Can you log something in the sign in successful block, before you can post_sign_in_flow, and also log something right after the post_sign_in_flow function call. Do you see both the logs?
s

sdekna

04/09/2023, 6:37 AM
yes I can see the logs... the
post_sign_in()
function only makes some user redirection logic... which works but until the redirect inside the
post_sign_in()
function fires I see the
500 url.clone is not a function
error
r

rp

04/09/2023, 6:38 AM
That’s odd. After emailPasswordSignIn returns, no code on the supertokens frontend SDK should run unless you call another function from our SDK or unless you make an API call
So I’m not sure if that error is from our SDK. Do you have a stack trace?
s

sdekna

04/09/2023, 7:07 AM
to be clear on where I am doing the console logs... here is how the function looks like:
js
export async function sign_in_handler(event) {
  try {
    const response = await emailPasswordSignIn({
      formFields: [
        {
          id: 'email',
          value: email
        },
        {
          id: 'password',
          value: password
        }
      ],
    });
    console.trace(response);
    if (response.status === 'FIELD_ERROR') {
      response.formFields.forEach((formField) => {
        if (formField.id === 'email') {
          console.log(formField.error)
        }
      });
    } else if (response.status === 'WRONG_CREDENTIALS_ERROR') {
      console.log('Email password combination is incorrect.')
    } else {
      // sign in successful. The session tokens are automatically handled by
      // the frontend SDK.
      console.log('sign in success')
      console.log('1')
      await post_sign_in_flow()
      console.log('2')

    }
  } catch (error: any) {
    // ....
  }
}
I do not get any errors logged in the console, only shown in the page... console tracing the response object give this:

https://cdn.discordapp.com/attachments/1094506506864562206/1094518887594328075/Screenshot_from_2023-04-09_08-58-50.png

r

rp

04/09/2023, 7:07 AM
Do you see these output? console.log('sign in success') console.log('1')
s

sdekna

04/09/2023, 7:13 AM

https://cdn.discordapp.com/attachments/1094506506864562206/1094520351687458916/Peek_2023-04-09_09-12.gif

yes... this is how the flow goes
this does not happen with sign_out
r

rp

04/09/2023, 7:17 AM
I see. so you do see console.log('2') as well. But i don't see any error output on the console.
s

sdekna

04/09/2023, 7:22 AM
yes no errors logged in the console... only on the page output... I can see a clone object in the response prototype... and grepping on the sdk code, I can see a couple of url.clone functions there... not sure how they relate or if they are connected.
Any ideas or walkarounds u can think of?
r

rp

04/09/2023, 7:23 AM
i don't think this is an issue with supertokens.
unless you can give us an error stack pointing to the supertokens SDK
So some way in which we can replicate this issue
s

sdekna

04/09/2023, 7:40 AM
I'll try to... thanks for your help
I think I found the problem, its as you mentioned not sdk related. The problem was that the form I was using to submit the login was using
method="POST"
which somehow invoked this behaviour... once I removed the
method="POST"
the problem disappeared. Thanks for the help again.