Handle logout #1072
-
|
I'm trying to implement authentication with urql and React, but I can't seem to grasp on what the flow would look like. As per the documentation: const getAuth = async ({ authState }) => {
if (!authState) {
const token = localStorage.getItem('token');
const refreshToken = localStorage.getItem('refreshToken');
if (token && refreshToken) {
return { token, refreshToken };
}
return null;
}
logout();
return null;
}When logout is called, I will remove the token from localStorage, but how will I notify the app that this has happened, and handle a redirect to the login page once again? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
Hey, In my opinion there a re a few ways to handle this, one being to rely on your internal redirecting. This means clearing your token from your storage and calling const getAuth = async ({ authState }) => {
if (!authState) {
const token = localStorage.getItem('token');
const refreshToken = localStorage.getItem('refreshToken');
if (token && refreshToken) {
return { token, refreshToken };
}
return null;
}
logout();
Router.push('/');
return null;
} |
Beta Was this translation helpful? Give feedback.
Hey,
In my opinion there a re a few ways to handle this, one being to rely on your internal redirecting. This means clearing your token from your storage and calling
window.location.reload()another option is to use your router/created history to route the user back to/or your own equivalent of that (this could be hard when your router isn't a global).