Skip to content

How can I log the user out without consent and redirect to homepage? #1005

Answered by jaaneh
l0c0luke asked this question in Help
Discussion options

You must be logged in to vote

If you're asking for e.g a "log out" button that instantly logs out, you can do something like this.

<div onClick={() => signOut()}>
    Sign out
</div>

By calling and invoking the signOut method, it will sign the user out on click. Paired with something like this (or your own redirect/auth check method) should work as expected.

export const getServerSideProps = async ({ req }) => {
  const session = await getSession({ req })

  if (!session) {
    return {
      props: {},
      redirect: {
        destination: '/',
        permanent: false
      }
    }
  }

  return {
    props: {}
  }
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by balazsorban44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1005 on December 30, 2020 01:57.