Skip to content

Commit

Permalink
oauth login button
Browse files Browse the repository at this point in the history
  • Loading branch information
sinamics committed Aug 9, 2024
1 parent 9189764 commit 0466d65
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/pages/auth/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import CredentialsForm from "~/components/auth/credentialsForm";
import Link from "next/link";
import { api } from "~/utils/api";

const Login = ({ title, oauthExlusiveLogin }) => {
const Login = ({ title, oauthExclusiveLogin, oauthEnabled }) => {
const currentYear = new Date().getFullYear();
const { data: options, isLoading: loadingRegistration } =
api.public.registrationAllowed.useQuery();
Expand All @@ -27,12 +27,15 @@ const Login = ({ title, oauthExlusiveLogin }) => {
<h3 className="text-xl font-semibold">Sign in to your account</h3>

<div className="space-y-5">
{!oauthExlusiveLogin && <CredentialsForm />}
{!oauthExclusiveLogin && <CredentialsForm />}

{oauthEnabled && (
<div>
{!oauthExclusiveLogin && <div className="divider">OR</div>}
<OauthLogin />
</div>
)}

<div>
{!oauthExlusiveLogin && <div className="divider">OR</div>}
<OauthLogin />
</div>
{options?.enableRegistration && !loadingRegistration ? (
<div className="pt-5">
<p className="mb-4">Don't have an account?</p>
Expand All @@ -58,11 +61,12 @@ interface Props {
export const getServerSideProps: GetServerSideProps<Props> = async (
context: GetServerSidePropsContext,
) => {
const oauthExlusiveLogin = process.env.OAUTH_EXCLUSIVE_LOGIN === "true";
const oauthExclusiveLogin = process.env.OAUTH_EXCLUSIVE_LOGIN === "true";
const oauthEnabled = !!process.env.OAUTH_ID && !!process.env.OAUTH_SECRET;

const session = await getSession(context);
if (!session || !session.user) {
return { props: { oauthExlusiveLogin } };
return { props: { oauthExclusiveLogin, oauthEnabled } };
}

if (session.user) {
Expand Down

0 comments on commit 0466d65

Please sign in to comment.