fix login not calling callback

This commit is contained in:
Dobromir Popov
2024-04-30 14:27:12 +03:00
parent f303ae193c
commit 60a3e770f9
2 changed files with 13 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import { getCsrfToken, signIn } from 'next-auth/react';
import React, { useState } from 'react';
import { useRouter } from 'next/router';
import Layout from '../../components/layout';
const { data: session } = useSession()
export default function SignIn({ csrfToken }) {
const [email, setEmail] = useState('');
@ -10,6 +11,16 @@ export default function SignIn({ csrfToken }) {
const [error, setError] = useState('');
const router = useRouter();
//handle callbackUrl
const { callbackUrl } = router.query;
if (callbackUrl) {
if (session) {
router.push(callbackUrl);
}
}
const handleSubmit = async (e) => {
e.preventDefault();