New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
(feat): custom signin page #6016
Changes from all commits
314ae6d
a2f2d46
efcb3a4
b2cf7e1
d0c9d3a
6d7227a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import BlankLayout from "@components/layouts/BlankLayout" | ||
import { getServerSession } from "next-auth/next" | ||
import { getProviders, signIn } from "next-auth/react" | ||
import Image from "next/image" | ||
import { authOptions } from "pages/api/auth/[...nextauth]" | ||
import { BsGithub } from "react-icons/bs" | ||
import { AiOutlineLock } from "react-icons/ai" | ||
|
||
|
||
export async function getServerSideProps(context) { | ||
const session = await getServerSession(context.req, context.res, authOptions); | ||
|
||
// if the user is logged in redirect, (note: don't redirect to the same page otherwise it'll be in a infinite loop) | ||
if (session) { | ||
return { redirect: { destination: "/account/statistics" } }; | ||
} | ||
|
||
const providers = await getProviders(); | ||
|
||
return { | ||
props: { providers: providers ?? [] }, | ||
} | ||
} | ||
|
||
|
||
export default function SignIn({ providers }) { | ||
|
||
const handleProviderIcon = (provider_name) => { | ||
if (provider_name === "GitHub") { | ||
return <BsGithub className="text-xl" /> | ||
} | ||
return <AiOutlineLock /> | ||
} | ||
|
||
return ( | ||
<div className="flex min-h-screen items-center justify-center px-4 py-12 sm:px-6 lg:px-8"> | ||
<div className="w-full max-w-sm space-y-8"> | ||
<Image | ||
width={50} | ||
height={50} | ||
className="mx-auto h-16 w-auto" | ||
src="/logo512.png" | ||
NiazMorshed2007 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
alt="Your Company" | ||
/> | ||
<h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-primary-medium"> | ||
<span className="text-secondary-medium"> Connect to your audience </span> | ||
with a single link | ||
</h2> | ||
{Object.values(providers).map((provider) => ( | ||
<button | ||
key={provider.name} | ||
onClick={() => signIn(provider.id)} | ||
className="group relative transition-all flex gap-4 items-center w-full justify-center rounded-md bg-primary-medium p-3 text-sm font-medium text-primary-low hover:bg-primary-medium/90 dark:hover:bg-primary-medium/60 outline-none" | ||
> | ||
{handleProviderIcon(provider.name)} Continue with {provider.name} | ||
</button> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
SignIn.getLayout = function getLayout(page) { | ||
return ( | ||
<BlankLayout> | ||
{page} | ||
</BlankLayout> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The formatting doesn't look quite right, can you check you are using our Prettier config in VScode There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep we use the default, that is fine, the plugin will work on save usually There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, but it doesn't fix the formatting. I've pinged on discord about this issue. |
||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A
switch
would be better here and then add adefault
at the end for a fallback login iconThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But for now maybe just add a return out side of the
if
with a default key/secure iconThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes 馃憤 , but you might want to add the same class to it also