mirror of
https://github.com/Xevion/bus-reminder.git
synced 2025-12-16 12:11:21 -06:00
Add basic index, complete login route with validation
This commit is contained in:
31
src/pages/index.tsx
Normal file
31
src/pages/index.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import {GetServerSidePropsContext, GetServerSidePropsResult, NextPage} from "next";
|
||||
import {z} from "zod";
|
||||
import {env} from "@/env/server.mjs";
|
||||
|
||||
type Props = {
|
||||
authenticated: boolean;
|
||||
}
|
||||
|
||||
export async function getServerSideProps({query}: GetServerSidePropsContext): Promise<GetServerSidePropsResult<Props>> {
|
||||
const parsedKey = z.string().safeParse(query?.key);
|
||||
|
||||
if (parsedKey.success && env.API_KEY === parsedKey.data)
|
||||
return {
|
||||
props: {
|
||||
authenticated: true
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
redirect: {
|
||||
destination: '/login',
|
||||
permanent: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const IndexPage: NextPage<Props> = ({authenticated}) => {
|
||||
return <div></div>
|
||||
}
|
||||
|
||||
export default IndexPage;
|
||||
Reference in New Issue
Block a user