how mongodb schema looks like with supertokens?
a
how mongodb schema looks like with supertokens?
r
Hey! We support mongodb only for the session recipe and nothing else.
We don’t have the mongodb schema documented, so the easiest way for you to see it is to connect it to the database and then create a new session.
a
hey thx for reaching out
we already use redis to store session lifetime token for shopify
r
ah right.
a
we've been studying which technologies to use for the database and we've come to the conclusion that maybe mongodb would be a good choice, since there aren't many relationships and it looks more like the json format.
we prefer a hosted solution so we don't have to deal with hosting
r
I see. In that case, you may want to use our managed service version in which we host the supertokens' db for you
So you can sign up to supertokens.com, and get a dedicated supertokens core for your app with all the features.
a
hmmm. Our app ise serverless in order to do it we need a rest api to fetch the sessions
r
What do you mean by "we need a rest api to fetch the sessions"?
a
in a serverless environment, in this case edge functions at vercel, thing have to go through rest apis indestead of libraries like @redis or @kakfa which depend from nodejs and not every nodejs function is available at the edge
r
hmmm i see
a
in our case we have a middleware
_middleware.ts
who fetch the session from shopify and checks if the user is authenticated.
r
So where do you intent to integrate the supertokens' node SDK?
In a separate service? Or in the edge functions itself?
a
on the edge it self, middlewares on nextjs when hosted by vercel runs on the edge
r
Right I see.
So in that case, you can follow our nextjs guide - it doesn't use the middleware feature yet, but uses the serverless API feature of nextjs
and you can use our session verification functions from the node SDK to do session verification easily.
a
I see
r
Here is an example of how session verification can be done: https://supertokens.com/docs/thirdpartyemailpassword/nextjs/session-verification/in-api
a
Edge middlewares are not meant for this, an edge middleware executes before a request is processed, if we your implementation requires to call an api to verify a session it is not cost effective. Instead they should interact with cookies as we do with shopify, we grab the cookie, checks if is valid and redirects to the shopify login or install page
https://next-auth.js.org is better suited for the job
r
right I see. In that case, you may want to do the following: - Enable JWTs in our session. - Send the JWT to your edge functions for verification - Verify the JWT using the public key (no IO required). - Continue the execution of the edge function. For the APIs that are required by the frontend for sign in, sign up, signout etc.. you can use our backend SDK in a node process that you host somewhere.
a
hmm that may work
r
yup!
Just curious, why don't you just use next-auth?
a
I asked my self that question
I think I just feel more secure if the authentication and session management where handled else here on a managed service
r
right. Alright
a
with next-auth we will be kinda "hosting" authentication on edge functions
r
yup. That is true
a
but isn't that that same when we wrap supertokens sdk to edge functions
r
that is.
That's why i suggested the other approach
which is just to send the JWT to edge functions and host a separate node process that uses our node SDK
in that way, you won't be hosting auth in edge functions.
a
ohright!
for my needs I don't think that we will be in any trouble because we don't have millions of customers
logging in at the same time
r
yea.. and logging in / out is a relatively rare operation anyway
a
I say like 70~ customers daily wont affect edge functions
r
that should not be a problem at all
a
I may see next-auth first as it supports redis
thx for your help
r
happy to help.
a
this conversation is downloadable?
i guess not
r
im not sure if you can do that via discord directly, but we have https://community.supertokens.com/ where this conversation will show up once this thread is archived
(it may take a day i think for it to sync up)
21 Views