mirror of
https://github.com/vernu/textbee.git
synced 2026-05-18 13:24:50 -04:00
fix(web): fix redirect query not redirecting after login issue
This commit is contained in:
@@ -4,10 +4,12 @@ import { Routes } from '@/config/routes'
|
||||
import { toast } from '@/hooks/use-toast'
|
||||
import { CredentialResponse, GoogleLogin } from '@react-oauth/google'
|
||||
import { signIn } from 'next-auth/react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { useRouter, useSearchParams } from 'next/navigation'
|
||||
|
||||
export default function LoginWithGoogle() {
|
||||
const router = useRouter()
|
||||
const searchParams = useSearchParams()
|
||||
const redirect = searchParams.get('redirect')
|
||||
|
||||
const onGoogleLoginSuccess = async (
|
||||
credentialResponse: CredentialResponse
|
||||
@@ -21,7 +23,7 @@ export default function LoginWithGoogle() {
|
||||
redirect: false,
|
||||
idToken: credentialResponse.credential,
|
||||
})
|
||||
router.push(Routes.dashboard)
|
||||
router.push(redirect ? decodeURIComponent(redirect) : Routes.dashboard)
|
||||
}
|
||||
|
||||
const onGoogleLoginError = () => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import Link from 'next/link'
|
||||
import { useSearchParams } from 'next/navigation'
|
||||
|
||||
import {
|
||||
Card,
|
||||
@@ -16,6 +17,9 @@ import LoginForm from '../(components)/login-form'
|
||||
import { Routes } from '@/config/routes'
|
||||
|
||||
export default function LoginPage() {
|
||||
const searchParams = useSearchParams()
|
||||
const redirect = searchParams.get('redirect')
|
||||
|
||||
return (
|
||||
<div className='flex items-center justify-center min-h-screen bg-gray-100 dark:bg-muted'>
|
||||
<Card className='w-[400px] shadow-lg'>
|
||||
@@ -53,7 +57,12 @@ export default function LoginPage() {
|
||||
<p className='text-sm text-gray-600'>
|
||||
Don't have an account?{' '}
|
||||
<Link
|
||||
href={Routes.register}
|
||||
href={{
|
||||
pathname: Routes.register,
|
||||
query: {
|
||||
redirect: redirect ? decodeURIComponent(redirect) : undefined,
|
||||
},
|
||||
}}
|
||||
className='font-medium text-blue-600 hover:underline'
|
||||
>
|
||||
Sign up
|
||||
|
||||
@@ -13,8 +13,12 @@ import {
|
||||
import LoginWithGoogle from '../(components)/login-with-google'
|
||||
import RegisterForm from '../(components)/register-form'
|
||||
import { Routes } from '@/config/routes'
|
||||
import { useSearchParams } from 'next/navigation'
|
||||
|
||||
export default function RegisterPage() {
|
||||
const searchParams = useSearchParams()
|
||||
const redirect = searchParams.get('redirect')
|
||||
|
||||
return (
|
||||
<div className='flex items-center justify-center min-h-screen bg-gray-100 dark:bg-muted'>
|
||||
<Card className='w-[450px] shadow-lg'>
|
||||
@@ -46,7 +50,12 @@ export default function RegisterPage() {
|
||||
<p className='text-sm text-gray-600'>
|
||||
Already have an account?{' '}
|
||||
<Link
|
||||
href={Routes.login}
|
||||
href={{
|
||||
pathname: Routes.login,
|
||||
query: {
|
||||
redirect: redirect ? decodeURIComponent(redirect) : undefined,
|
||||
},
|
||||
}}
|
||||
className='font-medium text-blue-600 hover:underline'
|
||||
>
|
||||
Sign in
|
||||
|
||||
Reference in New Issue
Block a user