any idea why my generated user auth token after a ...
# prisma-whats-new
t
any idea why my generated user auth token after a refresh is invalid? Shouldn’t be the token valid for a certain period of time?
a
After a refresh?
t
refresh of the browser
site
sorry reload
a
Okay, can you explain exactly what you're doing?
t
simple login with email password auth provider
get the token
save under localstorage and use it as bearer token inside header
everything works great
api calls everything
but if i do a reload of my page the token is not anymore valid
a
I think you have a problem passing the token to the api call
t
no magic:
networkInterface.use([ { applyMiddleware(req, next) { if (!req.options.headers) { req.options.headers = {}; // Create the header object if needed. } // get the authentication token from local storage if it exists req.options.headers.authorization = localStorage.getItem(‘token’) || null; next(); } } ])
apollo-client
a
Tokens are valid for 30 days
t
hmmm
this is what i am doing after the bootstrap to verify the session and to get user data
export const currentUserQuery = gql` query getUserData { user { id email phoneNumber surname lastname } }`
it gives me null
which shouldn’t
a
Can you create a topic on the forum and put your code fragments in there? https://www.graph.cool/forum/
I think you need the Bearer prefix by the way
Copy code
req.options.headers.authorization = localStorage.getItem(‘token’) ? `Bearer ${localStorage.getItem(‘token’)}` : null;
t
good point
haa ok i think this is the problem and of course the singin is working 😄
because it works with no auth 😉
a
yep
t
ok works ….great thanks
😎 1
!!