feat(frontend): log in with Discord
This commit is contained in:
parent
e4d028bbad
commit
4a8e1bb54f
8 changed files with 158 additions and 3 deletions
41
frontend/pages/login/index.tsx
Normal file
41
frontend/pages/login/index.tsx
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { GetServerSideProps } from "next";
|
||||
import { useRouter } from "next/router";
|
||||
import { useRecoilValue } from "recoil";
|
||||
import Head from "next/head";
|
||||
import fetchAPI from "../../lib/fetch";
|
||||
import { userState } from "../../lib/state";
|
||||
|
||||
interface URLsResponse {
|
||||
discord: string;
|
||||
}
|
||||
|
||||
export default function Login({ urls }: { urls: URLsResponse }) {
|
||||
const router = useRouter();
|
||||
|
||||
if (useRecoilValue(userState) !== null) {
|
||||
router.push("/");
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title key="title">Login - pronouns.cc</title>
|
||||
</Head>
|
||||
<a href={urls.discord}>Login with Discord</a>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
try {
|
||||
const urls = await fetchAPI<URLsResponse>("/auth/urls", "POST", {
|
||||
callback_domain: process.env.DOMAIN,
|
||||
});
|
||||
|
||||
return { props: { urls } };
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
||||
return { notFound: true };
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue