Validate user tokens on the backend #845
Answered
by
Nick-Mazuk
Nick-Mazuk
asked this question in
Questions
-
Is it possible to validate a user's session token on the backend? For instance, in Firebase, you can validate an ID token with admin.auth().verifyIdToken(idToken) Right now, I'm writing a function that only authenticated users should be able to access, so it would be extremely helpful if there's a way to do this. Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
Nick-Mazuk
Mar 9, 2021
Replies: 1 comment 2 replies
-
Turns out that since Supabase uses JWTs, you can validate it as you would any other JWT. Frontend: supabase.auth.session()?.accessToken // gets the JWT Backend import { verify } from 'jsonwebtoken'
// data is the contents of the JWT if valid
const data = const verify(token, supabase_jwt_secret) // throws error if invalid You can find the JWT secret in the Supabase dashboard. Settings > API > JWT Secret |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Nick-Mazuk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns out that since Supabase uses JWTs, you can validate it as you would any other JWT.
Frontend:
Backend
You can find the JWT secret in the Supabase dashboard. Settings > API > JWT Secret