Skip to content

Commit

Permalink
Add feature flag for Google Login (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zishan-7 authored Oct 14, 2024
1 parent 3e8b8bb commit 1a48f94
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 61 deletions.
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
VITE_API_BASE_URL=http://localhost:3000
VITE_CLERK_PUBLISHABLE_KEY=pk_test_b3B0aW1hbC1jaGlja2VuLTU3LmNsZXJrLmFjY291bnRzLmRldiQ
VITE_GOOGLE_REDIRECT_URL=https://optimal-chicken-57.clerk.accounts.dev/v1/oauth_callback
VITE_LOG_LEVEL=debug
51 changes: 26 additions & 25 deletions src/onboarding/Login.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Input } from '@nextui-org/react';
import { Button, Divider, Image, Input } from '@nextui-org/react';
import { Link, Navigate, useNavigate } from 'react-router-dom';
import { useSignIn, useUser } from '@clerk/clerk-react';
import { reduceState } from '../shared/helpers';
Expand Down Expand Up @@ -54,14 +54,13 @@ export default function Login() {
}
};

// const handleGoogleLogin = async () => {
// await signIn.authenticateWithRedirect({
// strategy: 'oauth_google',
// redirectUrl:
// 'https://hip-primate-84.clerk.accounts.dev/v1/oauth_callback',
// redirectUrlComplete: '/'
// });
// };
const handleGoogleLogin = async () => {
await signIn.authenticateWithRedirect({
strategy: 'oauth_google',
redirectUrl: import.meta.env.VITE_GOOGLE_REDIRECT_URL,
redirectUrlComplete: '/'
});
};

if (isSignedIn) {
return <Navigate to={'/'} />;
Expand All @@ -78,8 +77,6 @@ export default function Login() {
</p>
</div>

{/* <GoogleOneTap /> */}

<form
className="flex w-full flex-col items-center justify-center gap-y-5 rounded-lg border border-outline bg-content1 p-5 md:w-[31rem]"
onSubmit={handleSubmit(handleLogin)}
Expand Down Expand Up @@ -133,20 +130,24 @@ export default function Login() {
})}
/>

{/* <div className="flex w-full items-center gap-x-2">
<Divider className="w-[46.5%] bg-outline" />
<p>or</p>
<Divider className="w-[46.5%] bg-outline" />
</div> */}
{/* <Button
className="rounded-sm border border-outline"
fullWidth
onPress={handleGoogleLogin}
startContent={<Image src="/images/google.svg" />}
variant="bordered"
>
Continue with Google
</Button> */}
{localStorage.getItem('isGoogleOAuthEnabled') && (
<div className="flex w-full items-center gap-x-2">
<Divider className="w-[46.5%] bg-outline" />
<p>or</p>
<Divider className="w-[46.5%] bg-outline" />
</div>
)}
{localStorage.getItem('isGoogleOAuthEnabled') && (
<Button
className="rounded-sm border border-outline"
fullWidth
onPress={handleGoogleLogin}
startContent={<Image src="/images/google.svg" />}
variant="bordered"
>
Continue with Google
</Button>
)}

<Button
className="rounded-sm border border-secondary text-secondary hover:border-focus hover:text-focus"
Expand Down
73 changes: 37 additions & 36 deletions src/onboarding/Register.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Checkbox, cn, Input } from '@nextui-org/react';
import { Button, Checkbox, cn, Divider, Image, Input } from '@nextui-org/react';
import { Link, Navigate, useNavigate } from 'react-router-dom';
import { useSignUp, useUser } from '@clerk/clerk-react';
import { OTPInput } from 'input-otp';
Expand All @@ -12,8 +12,8 @@ export default function Register() {
handleSubmit,
getValues,
setError,
// clearErrors,
// reset,
clearErrors,
reset,
formState: { errors }
} = useForm();
const { isLoaded: isClerkLoaded, signUp, setActive } = useSignUp();
Expand Down Expand Up @@ -90,23 +90,22 @@ export default function Register() {
}
};

// const handleGoogleLogin = async () => {
// reset();
// if (!getValues('terms')) {
// setError('terms', {
// message: 'Please accept terms and conditions',
// type: 'required'
// });
// return;
// }
// clearErrors('terms');
// await signUp.authenticateWithRedirect({
// strategy: 'oauth_google',
// redirectUrl:
// 'https://hip-primate-84.clerk.accounts.dev/v1/oauth_callback',
// redirectUrlComplete: '/'
// });
// };
const handleGoogleLogin = async () => {
reset();
if (!getValues('terms')) {
setError('terms', {
message: 'Please accept terms and conditions',
type: 'required'
});
return;
}
clearErrors('terms');
await signUp.authenticateWithRedirect({
strategy: 'oauth_google',
redirectUrl: import.meta.env.VITE_GOOGLE_REDIRECT_URL,
redirectUrlComplete: '/'
});
};

if (isSignedIn) {
return <Navigate to={'/'} />;
Expand Down Expand Up @@ -181,8 +180,6 @@ export default function Register() {
</p>
</div>

{/* <GoogleOneTap /> */}

<form
className="flex w-full flex-col items-center justify-center gap-y-5 rounded-lg border border-outline bg-content1 p-5 md:w-[31rem]"
onSubmit={handleSubmit(handleSignUp)}
Expand Down Expand Up @@ -236,21 +233,25 @@ export default function Register() {
})}
/>

{/* <div className="flex w-full items-center gap-x-2">
<Divider className="w-[46.5%] bg-outline" />
<p>or</p>
<Divider className="w-[46.5%] bg-outline" />
</div> */}
{localStorage.getItem('isGoogleOAuthEnabled') && (
<div className="flex w-full items-center gap-x-2">
<Divider className="w-[46.5%] bg-outline" />
<p>or</p>
<Divider className="w-[46.5%] bg-outline" />
</div>
)}

{/* <Button
className="rounded-sm border border-outline"
fullWidth
onPress={handleGoogleLogin}
startContent={<Image src="/images/google.svg" />}
variant="bordered"
>
Continue with Google
</Button> */}
{localStorage.getItem('isGoogleOAuthEnabled') && (
<Button
className="rounded-sm border border-outline"
fullWidth
onPress={handleGoogleLogin}
startContent={<Image src="/images/google.svg" />}
variant="bordered"
>
Continue with Google
</Button>
)}

<div className="flex w-full flex-col">
<Checkbox
Expand Down

0 comments on commit 1a48f94

Please sign in to comment.