I’m trying to see if a user is logged in when load...
# prisma-whats-new
m
I’m trying to see if a user is logged in when loading a page. I currently use the following query with the
idToken
from Auth0. Though I notice there’s a mismatch between the token and what’s in the database, e.g.
idToken=a98d7f98af798d7f98afd798af897…
and
auth0IdToken=facebook|0982394802398409
Copy code
query ($auth0Id: String!) {
  user: User(auth0UserId: $auth0Id) {
    id
    name
  }
}
n
@mruzekw Yep, that's expected. If you paste the
idToken
here, you can see what information it contains: jwt.io
We're verifying the token using your secret Auth0 key. So the information in the token is not encoded, it's only signed. Hope that helps!
And the field is called
auth0UserId
and not
auth0IdToken
. Or what are you referring to with
auth0IdToken
?
m
Sorry I meant
auth0UserId
n
Yep 🙂
m
So can I use the
idToken
when loading the page? It works initially when loggin in or creating a user
n
Yea, so you can use that token for creating a new user and also for signing in as that user. Each time you login with Auth0 Lock, you get a new token that we can map to the user in your
User
model
m
Ohh okay, but when I refresh the page the user has to login again?
n
That depends on how you handle it. Is this about the web or mobile?
m
Web
n
https://www.graph.cool/docs/faq/graphcool-session-user-goij0cooqu The way to authenticate a user to the Graphcool API is setting the
Authorization
header with the token
if you put the token into
localStorage
, that should live through a page refresh
m
Yes, I’ve been referencing that here and there. Though I’m trying to translate into just pure HTTP queries since I’m using ClojureScript without Apollo
So I would use the token from auth0 as the
Authorization
token?
n
I see. Make sure to refer to some "central storage" in the Apollo middleware that sets the
Authorization
header. If you want that to live through page reloads, your central storage has to manage that.
Exactly! If the token is
myToken
, the
Authorization
header has to be set to
Bearer myToken
m
Ah okay, makes more sense now. I’ll give this a go. Thanks!
🙌 1
Since you’re here would this be any different with React Native?
n
no 🙂 only the "central storage" implementation, the logic is applicable there as well
m
Okay, cool