Hi, we are building an application where we are pl...
# support-questions-legacy
r
Hi, we are building an application where we are planning to use two different auth methods(email-password and passwordless) for two different use cases. Just want to confirm if it is possible to club these two?
r
hey @roushan_46400 when you say these are fro different use cases, but you also want to club them, what do you mean?
r
I mean two different auth methods like for admin tool we want to use email-password and for other users, we wanna use passwordless(magic link).
r
yup. That's certainly possible
r
Cool One more thing I would like to confirm that is that possible to create user before the magic link generation. We have a use case where we want to create a user as soon as the request comes, but he will be valid user once we approve them. So flow will be something like this: User requests access -> user should be created at SuperTokens Once admin approves that request at our end, we will trigger an magic lick to activate that user.
r
yup, this is possible as well.
r
How can we create the user? I am assuming, if I call this method: https://supertokens.com/docs/passwordless/common-customizations/disable-sign-up/passwordless-via-allow-list a user will be created. Is there any alternative to create a user in passwordless auth method?
r
We have passwordless.signInUp function exposed on the backend SDK using which you can create a user implicitly. See this: https://supertokens.com/docs/passwordless/common-customizations/disable-sign-up/passwordless-via-invite-link
r
Want to add one more thing, we want to use supertokens for main website & admin tool login. Can we use different session configurations for both?
r
do they both have different backends?
r
No, we are planning to use the same backend auth service for both of them.
r
ok, and the thing you want to configure differently is the session timeout I assume? Or something else?
r
Yes, for now timeout only. But will it cause any issue if want to configure anything else?
r
well, no issues as such.
for timeout, we have a global value thats set on the core
but you can add your own custom claim in the access token and check that for admin users for example
so the global value set on the core will be the large timeout of the two session configs
and on top of that, post session verification, if it's the admin, you can check the
iat
claim of the access token and then compare that to the custom timeout for admins.
and if the timeout has reached, call session.revokeSession() and send a 401.
r
Okay So, you are saying to add a custom claim for the token which has shorter timeout and since the global value is also set, the other token will expire at that.
r
Yup.
r
What if we want to configure session refresh and session storage data in the session configuration. Do they also have some global values that we need to set? Or just providing custom claim on them too will work?
r
Session refresh data?
You mean how often it refreshes?
r
yes
r
Ah right. So that can also be done via a custom claim. Basically if you send a 401 to a frontend, our SDK will attempt a session refresh.
(Assuming you did not call session.revokeSession before sending a 401)
r
And what if we want to store this data at different places?
I mean storing these session tokens.
r
So supertokens only stores the hash of the refresh token in our db. On the frontend, the access and refresh tokens are in httpOnly cookies by default
What do you want to change from this?
r
Currently, I don't want any. Yes, JWT tokens are stored in cookies itself. But just wanted to confirm I we in future want to change to have different storage type (its highly unlikely but just want to confirm)?
r
yea you can. We have header based auth as well which returns the tokens in the response headers (not in cookies), and that can be stored on the frontend whererver you like.
r
Cool. Thanks for your quick support.
a
@rp_st Is it a good idea to run separate Supertokens backends with distinct configurations (connected to the same database) for Admins and our users? Additionally, do you have any suggestions on how to efficiently route requests between them?
r
Whats your use case again?
a
@rp_st Wanted to have different access/refresh token expiry for different roles (users & internal admins).
r
that can be done by setting the config in the core to the higer value, and then injecting a custom claim in the access token roles which need a lower expiration value. Then post session verification, manually check the value of the custom claim and if it's expired, revoke the session and return a 401 from the API.
4 Views