mirror of
https://github.com/vernu/textbee.git
synced 2026-02-20 15:44:31 -05:00
chore(web): redirect unauthenticated users to signin in checkout page
This commit is contained in:
@@ -2,12 +2,16 @@
|
||||
|
||||
import { useState, useEffect } from 'react'
|
||||
import httpBrowserClient from '@/lib/httpBrowserClient'
|
||||
import { useSession } from 'next-auth/react'
|
||||
import { redirect } from 'next/navigation'
|
||||
|
||||
export default function CheckoutPage({ params }) {
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
const planName = params.planName as string
|
||||
|
||||
const { data: session } = useSession()
|
||||
|
||||
useEffect(() => {
|
||||
const initiateCheckout = async () => {
|
||||
try {
|
||||
@@ -25,6 +29,10 @@ export default function CheckoutPage({ params }) {
|
||||
initiateCheckout()
|
||||
}, [planName])
|
||||
|
||||
if (!session?.user) {
|
||||
return redirect(`/login?redirect=${window.location.href}`)
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <div className='text-red-500'>{error}</div>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user