|
|
|
@@ -1,26 +1,19 @@ |
|
|
|
import { getServerSession } from "next-auth"; |
|
|
|
import { redirect } from "next/navigation"; |
|
|
|
import { authOptions } from "@/config/authConfig"; |
|
|
|
import { I18nProvider } from "@/i18n"; |
|
|
|
import LoginPage from "@/components/LoginPage/LoginPage"; |
|
|
|
import LoginRedirectIfAuthenticated from "@/components/LoginPage/LoginRedirectIfAuthenticated"; |
|
|
|
|
|
|
|
type Props = { searchParams?: Promise<{ [key: string]: string | string[] | undefined }> }; |
|
|
|
|
|
|
|
const Login: React.FC<Props> = async ({ searchParams }) => { |
|
|
|
const session = await getServerSession(authOptions); |
|
|
|
const params = await searchParams; |
|
|
|
const sessionParam = params?.session; |
|
|
|
const forceLogin = sessionParam === "expired" || (Array.isArray(sessionParam) && sessionParam.includes("expired")); |
|
|
|
const now = Math.floor(Date.now() / 1000); |
|
|
|
const notExpired = !session?.exp || session.exp > now; |
|
|
|
if (session?.user && notExpired && !forceLogin) { |
|
|
|
redirect("/"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Redirect when already authenticated is done in LoginRedirectIfAuthenticated |
|
|
|
* (client-side with useSearchParams) so it works in production where server |
|
|
|
* searchParams can be undefined after build. |
|
|
|
*/ |
|
|
|
const Login: React.FC = () => { |
|
|
|
return ( |
|
|
|
<I18nProvider namespaces={["login"]}> |
|
|
|
<LoginPage /> |
|
|
|
</I18nProvider> |
|
|
|
<LoginRedirectIfAuthenticated> |
|
|
|
<I18nProvider namespaces={["login"]}> |
|
|
|
<LoginPage /> |
|
|
|
</I18nProvider> |
|
|
|
</LoginRedirectIfAuthenticated> |
|
|
|
); |
|
|
|
}; |
|
|
|
|
|
|
|
|