google auth on nextjs

i am using next/router to push to /u/dashboard if there is no error on creating user with google auth. the problem is the redirect reverts back to localhost:3000/# on success. after then a full reload get me to /u/dashboard.

// /index.tsx (login page)
const withAuthProvider = async () => {
  const { error } = await supabase.auth.signIn({ provider: 'google' })
  if (error) return setToast({ text: error.message, type: 'error' })
  router.push('/u/dashboard')
}

export const getServerSideProps: GetServerSideProps = async (context) => {
  const { user } = await getUser(context)
  if (user) return { props: {}, redirect: { destination: '/u/dashboard', permanent: false } }
  return { props: {} }
}


// /u/dashboard.tsx (protected page)
export const getServerSideProps: GetServerSideProps = withPageAuth({
  redirectTo: '/',
  async getServerSideProps(context) {
    const { user } = await getUser(context)
    return { props: { user } }
  },
})
Was this page helpful?