Skip to content
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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions pages/api/auth/[...nextauth].js
Expand Up @@ -46,6 +46,9 @@ export const authOptions = {
return session;
},
},
pages: {
signIn: "/auth/signin",
}
};

export default NextAuth(authOptions);
69 changes: 69 additions & 0 deletions pages/auth/signin.js
@@ -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") {
Copy link
Member

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 a default at the end for a fallback login icon

Copy link
Member

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 icon

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean like this?

const handleProviderIcon = (provider_name) => {
        if (provider_name === "GitHub") {
            return <BsGithub className="text-xl" />
        }

        return <LockIcon />
    }

Copy link
Member

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

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>
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done the other requested changes. But before I commit I've the issue with prettier still. Is the configuration for prettier is the .prettierrc file? I got it empty

image

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

)
}