Auth Solution

Researching token vs session based auth has been a pain. In my "design" i have two services, an api and a websocket and theres a possibility i will have a third, i need auth on all of these. Session auth seems to be the most basic, it also seems like it would be a pain to deal with as, afaik, you cant share cookies between domains. and everything ive read says you shouldnt store sessions in local storage. im very unsure of token based auth, i can find a lot of articles on it, but not really any that explain it in a way i properly understand. These services will be used in a a spa and mobile app. i would like to be able to logout clients from the server and clients to be able to remotely logout their other devices. could someone give me a good explanation/comparison and help me find the correct solution?
3 Replies
Sybatron
Sybatron•13mo ago
I think the sessions are usually in the db 🤔 from what I've seen So you can invalidate them all when password is changed or some other trigger
nozadev
nozadev•13mo ago
I don't understand how/why NextAuth sessions are stored in db, where can I research this?
Aland
Aland•13mo ago
You can share cookies between domains, but i recommend modifying your API to use the authorization header, simply put the token in the authorization header when making a request, and in your API route code instead of reading the session from the cookie read it from the authorization header. And to invalidate the sessions as @Sybatron said you just store all the sessions in the DB, And invalidate them based on a condition or manually. For example when the password gets changed you'll have to invalidate all the login sessions associated with that account.
Want results from more Discord servers?
Add your server
More Posts
Firebase signIn issue in React Native Expo production build - Crashes after selecting Google accountI am facing a critical issue in my React Native app where the app crashes abruptly after selecting aNext 13 App Dir, performance benefitsHello, are there really any performance benefits using server components and the app directory compaDo you use Prisma data-proxy for your T3 app?I found out the service only have two locations (Virginia and Frankfurt, if I’m not mistaken). And ILink won't navigate to app/not-found.tsx in app dirHi I made a sandbox example to demo this https://codesandbox.io/p/sandbox/elastic-julien-q8713m?filePassing Array of Strings to the backendI am tryna to pass a string of ids to the backend so I can connect them, but the array is not being NextJS with Server Components & React NativeIf I want to make an app that has both a web version in next js as well as a mobile version in reactCan somebody help recommend how to use 'npx prisma db push'.Everytime it shows the following error inspite of my several attempts of adding prisma.schema in my [TRPC or Prisma or React Native issue?] Do not know how to serialize a BigIntI og started a thread on the TRPC discord but am also posting here to see if anyone else has a betteCI error when importing static image filesI noticed a strange issue with my CI today. In one of the files, I am importing a jpg to later use iHow can I build interactive blog posthello friends I'm planning to build an interactive blog where I'm completely free to build interacti