© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
2 replies
harshcut

google auth on nextjs

i am using
next/router
next/router
to push to
/u/dashboard
/u/dashboard
if there is no error on creating user with google auth. the problem is the redirect reverts back to
localhost:3000/#
localhost:3000/#
on success. after then a full reload get me to
/u/dashboard
/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: {} }
}
// /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 } }
  },
})
// /u/dashboard.tsx (protected page)
export const getServerSideProps: GetServerSideProps = withPageAuth({
  redirectTo: '/',
  async getServerSideProps(context) {
    const { user } = await getUser(context)
    return { props: { user } }
  },
})
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

google auth fail
SupabaseSSupabase / help-and-questions
5mo ago
Nextjs with auth-ui
SupabaseSSupabase / help-and-questions
3y ago
nextjs auth wihtout helpers
SupabaseSSupabase / help-and-questions
4y ago
Nextjs Auth Helper Error
SupabaseSSupabase / help-and-questions
4y ago