supertokens / supertokens-flutter

Flutter SDK for SuperTokens
https://supertokens.com
Other
14 stars 10 forks source link

Session does not exist #51

Closed ttarbox closed 9 months ago

ttarbox commented 9 months ago

I'm able to send and verify an SMS OTP in my Flutter app, but I'm not able to get any session info on subsequent calls. Also, I'm using the HTTP Client and it does not inject a the Authentication header on requests to my backend.

What am I missing?

rishabhpoddar commented 9 months ago

It's likely a mis config from your end. Make sure that the apiDomain configured is the apiDomain that you use when making the sign in API call.

Also, make sure that you have added our interceptor as shown in the docs.

ttarbox commented 9 months ago

It certainly was a mis-config on my end. I am now able to call getUserId() successfully. However, calls to await SuperTokens.getAccessToken() directly after that still return null.

Thoughts?

rishabhpoddar commented 9 months ago

Can i see the supertokens.init config on the frontend?

ttarbox commented 9 months ago
SuperTokens.init(
        apiDomain: "https://<REMOVED>.ngrok-free.app",
        apiBasePath: "/auth",
        tokenTransferMethod: SuperTokensTokenTransferMethod.HEADER);
  }
ttarbox commented 9 months ago

On the backend, I simply have: Session.init()

Stepping through the code on the front-end I see that the access token is still be delivered via sAccessToken cookie. I also confirmed that the st-auth-mode header is set to header on the outgoing request, but I still only get the cookie access code.

Screenshot 2023-11-29 at 12 42 52 PM
rishabhpoddar commented 9 months ago

Strange. A few questions:

ttarbox commented 9 months ago

I'm using "supertokens-node": "^12.1.4" with fastify, based off of this example: https://github.com/lirantal/fastify-supertokens-example

The request headers for the /auth/signinup/code request are: {Content-type: application/json; charset=utf-8, st-auth-mode: header, cookie: }

rishabhpoddar commented 9 months ago

Ah! So the version of the node SDK that supports non cookie based auth is 13.0.0. Please upgrade it (make sure to see the changlog since it's a breaking change from the version you use) and try again.

ttarbox commented 9 months ago

That was it! Thank you!