SuperTokens with Serverless
# support-questions
d
coes super token work on serverless ? like heroku ?
nothing in your search bar
n
Hi, Yes we do work with serverless frameworks, while we dont have dedicated guides for Heroku you can ask questions here if you run into any issues
d
ok thanks
Copy code
md
com.supertokens {t: "2023-04-17T08:10:31.758Z", message: "doesSessionExist: called", supertokens-website-ver: "16.0.4"}
logger.js:31 com.supertokens {t: "2023-04-17T08:10:31.758Z", message: "FrontToken.getTokenInfo: called", supertokens-website-ver: "16.0.4"}
logger.js:31 com.supertokens {t: "2023-04-17T08:10:31.758Z", message: "getFrontToken: called", supertokens-website-ver: "16.0.4"}
logger.js:31 com.supertokens {t: "2023-04-17T08:10:31.758Z", message: "getLocalSessionState: called", supertokens-website-ver: "16.0.4"}
logger.js:31 com.supertokens {t: "2023-04-17T08:10:31.759Z", message: "getFrontTokenFromCookie: called", supertokens-website-ver: "16.0.4"}
logger.js:31 com.supertokens {t: "2023-04-17T08:10:31.759Z", message: "getLocalSessionState: returning NOT_EXISTS since frontToken was cleared but lastAccessTokenUpdate exists", supertokens-website-ver: "16.0.4"}
logger.js:31 com.supertokens {t: "2023-04-17T08:10:31.759Z", message: "getFrontToken: Returning because sIRTFrontend != EXISTS", supertokens-website-ver: "16.0.4"}
logger.js:31 com.supertokens {t: "2023-04-17T08:10:31.759Z", message: "getLocalSessionState: called", supertokens-website-ver: "16.0.4"}
logger.js:31 com.supertokens {t: "2023-04-17T08:10:31.759Z", message: "getFrontTokenFromCookie: called", supertokens-website-ver: "16.0.4"}
logger.js:31 com.supertokens {t: "2023-04-17T08:10:31.759Z", message: "getLocalSessionState: returning NOT_EXISTS since frontToken was cleared but lastAccessTokenUpdate exists", supertokens-website-ver: "16.0.4"}
logger.js:31 com.supertokens {t: "2023-04-17T08:10:31.759Z", message: "doesSessionExist: access token does not exist locally", supertokens-website-ver: "16.0.4"}
com.supertokens {t: "2023-04-17T08:10:31.759Z", message: "getLocalSessionState: returning NOT_EXISTS since frontToken was cleared but lastAccessTokenUpdate exists", supertokens-website-ver: "16.0.4"}
com.supertokens {t: "2023-04-17T08:10:31.759Z", message: "getLocalSessionState: returning NOT_EXISTS since frontToken was cleared but lastAccessTokenUpdate exists", supertokens-website-ver: "16.0.4"}
com.supertokens {t: "2023-04-17T08:10:31.759Z", message: "doesSessionExist: access token does not exist locally", supertokens-website-ver: "16.0.4"}
n
Can you explain what issue you are facing in terms of use case?
d
I cannot login I am in a paas like heroku that don't have session
it cannot fetch the session ( look like you are based on to
n
Ok just to make sure I understand correctly. - You call the login endpoint and get a valid response - Then you call another endpoint which says you dont have a session?
d
i try to call the /aith/signin -> it cannot get the session from the backend
I run a python app on clever cloud
n
Can you post the full response of the sign in endpoint? (including headers etc)
d

https://cdn.discordapp.com/attachments/1097427946853109780/1097437562282455110/Screenshot_20230417_102456.png

Copy code
js
const session = await Session.doesSessionExist();
when I do this it return me false in the after login
it should be true ?
n
Can you post the config you pass to SuperTokens init on both the frontend and backend?
d
front end
Copy code
js
SuperTokens.init({
  enableDebugLogs: true,
  appInfo: {
    appName: "formelegal",
    apiDomain: env.VUE_APP_BASE_URL,
    apiBasePath: "/auth",
  },
  recipeList: [
    Session.init({
      tokenTransferMethod: "header",
    }),
    ThirdPartyEmailPassword.init(),
    EmailPassword.init(),
  ],
})
backend
Copy code
py
init(
    app_info=InputAppInfo(
        app_name="formelegal",
        api_domain=env.SUPER_TOKEN_API_DOMAIN,
        website_domain=env.SUPER_TOKEN_WEBSITE_DOMAIN,
        api_base_path="/auth",
        website_base_path="/auth"
    ),
    supertokens_config=SupertokensConfig(
        connection_uri=env.SUPER_TOKEN_CONNECTION_URI,
        api_key=env.SUPER_TOKEN_API_KEY
    ),
    framework='fastapi',
    recipe_list=[
        dashboard.init(),
        session.init(get_token_transfer_method=get_token_transfer_method),
        thirdpartyemailpassword.init(
            sign_up_feature=thirdpartyemailpassword.InputSignUpFeature(
                form_fields=[InputFormField(id='firstname'), InputFormField(id='lastname'), InputFormField(id='phone')]
            ),
            override=thirdpartyemailpassword.InputOverrideConfig(
                apis=override_apis
            )
        ),
        emailpassword.init()
    ],
    mode='wsgi'  # use wsgi if you are running using gunicorn
)
n
How have you defined
get_token_transfer_method
?
d
Copy code
py

def get_token_transfer_method(req: BaseRequest, for_create_new_session: bool, user_context: Dict[str, Any]):
    # OR use session.init(get_token_transfer_method=lambda *_: "header")
    return "header"
n
Perhaps @porcellus can help better here
d
sorry I will move back to aws with api gateway
I think its more hassle free
thanks for all and good luck
so it's return me the field but always response false
Copy code
js
com.supertokens {t: "2023-04-17T09:45:05.479Z", message: "doesSessionExist: access token does not exist locally", supertokens-website-ver: "16.0.4"}
Copy code
js
com.supertokens {t: "2023-04-17T09:45:05.479Z", message: "getLocalSessionState: returning NOT_EXISTS since frontToken was cleared but lastAccessTokenUpdate exists", supertokens-website-ver: "16.0.4"}
p
hi
return me in the field?
d
try it
Copy code
js
const session = await Session.doesSessionExist();
it's return me false whathever , but localhost it's ok
I am using vuejs for front end and python for backend
p
oh, so it works on localhost?
d
yess
and http api call
p
since you are doing this in serverless, do you have this deployed somewhere I could check it? it may speed things up
d
in paas
usualy how you deploy super token apps ?
p
I'm not sure about statistics, we provide support for self-hosted, serverless, and I think paas shouldn't be any different.
d
usualy how you user deploy them apps ? 🙂
p
Like I said, I'm not sure about stats, I'll ask.
Anyway, can you provide me debug logs made during the login call?
or is there a public link I could check out?
d
I thnk its my front end
I have no error and all is ok in the logs
p
I meant the debug logs on the frontend
d
Copy code
js
com.supertokens {t: "2023-04-17T10:05:29.035Z", message: "onUnauthorisedResponse: local session doesn't exist, so removing anti-csrf and sFrontToken", supertokens-website-ver: "16.0.4"}
Copy code
js
com.supertokens {t: "2023-04-17T10:05:29.033Z", message: "getLocalSessionState: returning NOT_EXISTS since frontToken was cleared but lastAccessTokenUpdate exists", supertokens-website-ver: "16.0.4"}

https://cdn.discordapp.com/attachments/1097427946853109780/1097463376805900288/Screenshot_20230417_120728.png

p
there should be a lot of these logs, please either copy the entire text or there is a save as option if you right click the console
that cookie is not set by us.
ok I see
p
@rp can answer the deployment question
(I'm checking out your logs)
d
do i need to be https for production ?
r
> usualy how you user deploy them apps ? For self hosted, Via docker, in ec2 instance. However, using our managed service is simpler
p
I'd always recommend https for production, but I don't think it's strictly necessary.
Checking out your logs: your deployed frontend seems to not have the
tokenTransferMethod: "header"
config
d
it's not insecure ?
p
it is in general what I meant is that it's not required by supertokens I think.
d
I have a problem with same site
ok its my provider with add a cookies
now its strange it refresh everytime the session !
p
refresh every time the session? you mean on every page reload?
or do you mean it's continously refreshing?
d
yes
p
which one?
d
signinUser on session
p
I'm not sure what you mean by that
d
i tell you after
p
ok
d
it does always an event loop
like when you start the login => never stop after and search the token
in the backend
Copy code
py
INFO:     127.0.0.1:43654 - "POST /auth/session/refresh HTTP/1.1" 200 OK
com.supertokens {"t": "2023-04-17T14:38:48.692Z", "sdkVer": "0.12.6", "message": "middleware: Started", "file": "supertokens.py:458"}

com.supertokens {"t": "2023-04-17T14:38:48.692Z", "sdkVer": "0.12.6", "message": "middleware: requestRID is: session", "file": "supertokens.py:471"}

com.supertokens {"t": "2023-04-17T14:38:48.692Z", "sdkVer": "0.12.6", "message": "middleware: Checking recipe ID for match: dashboard", "file": "supertokens.py:482"}

com.supertokens {"t": "2023-04-17T14:38:48.692Z", "sdkVer": "0.12.6", "message": "middleware: Checking recipe ID for match: session", "file": "supertokens.py:482"}

com.supertokens {"t": "2023-04-17T14:38:48.693Z", "sdkVer": "0.12.6", "message": "middleware: Matched with recipe ID: session", "file": "supertokens.py:504"}

com.supertokens {"t": "2023-04-17T14:38:48.693Z", "sdkVer": "0.12.6", "message": "middleware: Request being handled by recipe. ID is: /session/refresh", "file": "supertokens.py:516"}

com.supertokens {"t": "2023-04-17T14:38:48.693Z", "sdkVer": "0.12.6", "message": "refreshSession: Started", "file": "recipe/session/recipe_implementation.py:492"}

com.supertokens {"t": "2023-04-17T14:38:48.693Z", "sdkVer": "0.12.6", "message": "refreshSession: got refresh token from cookie", "file": "recipe/session/recipe_implementation.py:506"}

com.supertokens {"t": "2023-04-17T14:38:48.694Z", "sdkVer": "0.12.6", "message": "refreshSession: getTokenTransferMethod returned: any", "file": "recipe/session/recipe_implementation.py:515"}

com.supertokens {"t": "2023-04-17T14:38:48.694Z", "sdkVer": "0.12.6", "message": "refreshSession: using cookie transfer method", "file": "recipe/session/recipe_implementation.py:532"}
p
event loop? I think there are two issues: 1. You call
doesSessionExist
on every render and getting the result seems to be triggering the render once again 2. For some reason saving the cookies fail. It didn't show in the config you pasted here, but I think you've set something as the
sessionTokenFrontendDomain
that doesn't match the current domain.
d
I set the headers as bearer => need to set it as cookies again
next week I will look to the sdf why it doesnt set properly when you have nothing into
need to set it again in session.init()
thanks for your help ! 🙂