Skip to content

Handle logout #1072

Answered by JoviDeCroock
maxfahl asked this question in Q&A
Oct 20, 2020 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

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).

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;
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@maxfahl
Comment options

@JoviDeCroock
Comment options

@maxfahl
Comment options

Answer selected by JoviDeCroock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants