|
|
@@ -6,7 +6,8 @@ import Stack from "@mui/material/Stack"; |
|
|
|
import TextField from "@mui/material/TextField"; |
|
|
|
import Typography from "@mui/material/Typography"; |
|
|
|
import { TFunction } from "i18next"; |
|
|
|
import { signIn } from "next-auth/react"; |
|
|
|
import { Session } from "next-auth"; |
|
|
|
import { getSession, signIn } from "next-auth/react"; |
|
|
|
import { useRouter } from "next/navigation"; |
|
|
|
import { useEffect, useState } from "react"; |
|
|
|
import { SubmitHandler, useForm } from "react-hook-form"; |
|
|
@@ -17,6 +18,10 @@ type LoginFields = { |
|
|
|
password: string; |
|
|
|
}; |
|
|
|
|
|
|
|
type SessionWithAbilities = { |
|
|
|
abilities: string[] |
|
|
|
} & Session | null |
|
|
|
|
|
|
|
// Error codes in https://next-auth.js.org/configuration/pages#sign-in-page |
|
|
|
const getHumanFriendlyErrorMessage = ( |
|
|
|
t: TFunction, |
|
|
@@ -53,8 +58,16 @@ const LoginForm: React.FC = () => { |
|
|
|
setServerError(res.error); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// set auth to local storage |
|
|
|
const session = await getSession() as SessionWithAbilities |
|
|
|
|
|
|
|
// console.log(session) |
|
|
|
window.localStorage.setItem("abilities", JSON.stringify(session?.abilities)) |
|
|
|
|
|
|
|
const callbackUrl = |
|
|
|
new URLSearchParams(window.location.search).get("callbackUrl") || "/"; |
|
|
|
new URLSearchParams(window.location.search).get("callbackUrl") || "/"; |
|
|
|
|
|
|
|
router.push(callbackUrl); |
|
|
|
}; |
|
|
@@ -62,7 +75,7 @@ const LoginForm: React.FC = () => { |
|
|
|
useEffect(()=> { |
|
|
|
// clean abilities before login |
|
|
|
window.localStorage.removeItem("abilities") |
|
|
|
}) |
|
|
|
}, []) |
|
|
|
|
|
|
|
return ( |
|
|
|
<Stack |
|
|
|