Skip to content

Commit 89d4c52

Browse files
authored
chore(social-login): disable social login buttons when env vars are not set (#7238)
1 parent f2e19d3 commit 89d4c52

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

ui/app/(auth)/sign-in/page.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { AuthForm } from "@/components/auth/oss";
2+
import { isGithubOAuthEnabled, isGoogleOAuthEnabled } from "@/lib/helper";
23

34
const SignIn = () => {
4-
return <AuthForm type="sign-in" />;
5+
return (
6+
<AuthForm
7+
type="sign-in"
8+
isGoogleOAuthEnabled={isGoogleOAuthEnabled}
9+
isGithubOAuthEnabled={isGithubOAuthEnabled}
10+
/>
11+
);
512
};
613

714
export default SignIn;

ui/app/(auth)/sign-up/page.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { AuthForm } from "@/components/auth/oss";
2+
import { isGithubOAuthEnabled } from "@/lib/helper";
3+
import { isGoogleOAuthEnabled } from "@/lib/helper";
24
import { SearchParamsProps } from "@/types";
35

46
const SignUp = ({ searchParams }: { searchParams: SearchParamsProps }) => {
@@ -7,7 +9,14 @@ const SignUp = ({ searchParams }: { searchParams: SearchParamsProps }) => {
79
? searchParams.invitation_token
810
: null;
911

10-
return <AuthForm type="sign-up" invitationToken={invitationToken} />;
12+
return (
13+
<AuthForm
14+
type="sign-up"
15+
invitationToken={invitationToken}
16+
isGoogleOAuthEnabled={isGoogleOAuthEnabled}
17+
isGithubOAuthEnabled={isGithubOAuthEnabled}
18+
/>
19+
);
1120
};
1221

1322
export default SignUp;

ui/components/auth/oss/auth-form.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ export const AuthForm = ({
2525
type,
2626
invitationToken,
2727
isCloudEnv,
28+
isGoogleOAuthEnabled,
29+
isGithubOAuthEnabled,
2830
}: {
2931
type: string;
3032
invitationToken?: string | null;
3133
isCloudEnv?: boolean;
34+
isGoogleOAuthEnabled?: boolean;
35+
isGithubOAuthEnabled?: boolean;
3236
}) => {
3337
const formSchema = authFormSchema(type);
3438
const router = useRouter();
@@ -302,9 +306,11 @@ export const AuthForm = ({
302306
variant="bordered"
303307
as="a"
304308
href={getAuthUrl("google")}
309+
isDisabled={!isGoogleOAuthEnabled}
305310
>
306311
Continue with Google
307312
</Button>
313+
308314
<Button
309315
startContent={
310316
<Icon
@@ -316,6 +322,7 @@ export const AuthForm = ({
316322
variant="bordered"
317323
as="a"
318324
href={getAuthUrl("github")}
325+
isDisabled={!isGithubOAuthEnabled}
319326
>
320327
Continue with Github
321328
</Button>

ui/lib/helper.ts

+8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ export const getAuthUrl = (provider: AuthSocialProvider) => {
3434
return url.toString();
3535
};
3636

37+
export const isGoogleOAuthEnabled =
38+
process.env.SOCIAL_GOOGLE_OAUTH_CLIENT_ID !== "" &&
39+
process.env.SOCIAL_GOOGLE_OAUTH_CLIENT_SECRET !== "";
40+
41+
export const isGithubOAuthEnabled =
42+
process.env.SOCIAL_GITHUB_OAUTH_CLIENT_ID !== "" &&
43+
process.env.SOCIAL_GITHUB_OAUTH_CLIENT_SECRET !== "";
44+
3745
export async function checkTaskStatus(
3846
taskId: string,
3947
): Promise<{ completed: boolean; error?: string }> {

0 commit comments

Comments
 (0)