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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(SignInButtons): simplify sign-in handlers #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions frontend/src/components/SignInButtons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { useNavigate } from "react-router-dom";
import { signInWithPopup, GoogleAuthProvider, OAuthProvider, GithubAuthProvider, User } from "firebase/auth";
import { auth } from "../../config/firebase";



const SignInGoogle = async () => {
const provider = new GoogleAuthProvider();
return signInWithPopup(auth, provider);
Expand Down Expand Up @@ -39,20 +37,8 @@ const SignInGitHub = () => {
return signInWithPopup(auth, provider);
}

export const SignInButtons = ({isBroken}: {isBroken: boolean}) => {
export const SignInButtons = ({ isBroken }: { isBroken: boolean }) => {
const navigate = useNavigate();
const handleSignIn = async (provider: String) => {
switch (provider) {
case 'Google': await SignInGoogle().then((crendentialUser) => redirect(crendentialUser.user));
break;
case 'Apple': await SignInApple().then((crendentialUser) => redirect(crendentialUser.user));
break;
case 'Microsoft': await SignInMicrosoft().then((crendentialUser) => redirect(crendentialUser.user));
break;
case 'GitHub': await SignInGitHub().then((crendentialUser) => redirect(crendentialUser.user));
break;
}
}

const redirect = (user: User) => {
if (user?.emailVerified) {
Expand All @@ -63,37 +49,51 @@ export const SignInButtons = ({isBroken}: {isBroken: boolean}) => {
};

const styles = isBroken ? SignInButtonsStyles.buttonMobile : SignInButtonsStyles.button;

return (
<div
<div
style={isBroken ? {
...SignInButtonsStyles.container, flexDirection: 'column'
} : SignInButtonsStyles.container}
>
<Button
style={styles}
onClick={() => handleSignIn('Google')}
onClick={async () => await SignInGoogle().then((credentialUser) =>
redirect(credentialUser.user)
)}
icon={<img src={googleLogo} alt="Logo da Google." width="15px" />}
>
Google
</Button>
<Button
style={styles}
onClick={() => handleSignIn('Apple')}
onClick={async () =>
await SignInApple().then((credentialUser) =>
redirect(credentialUser.user)
)
}
icon={<img src={appleLogo} alt="Logo da Apple." width="15px" />}
>
Apple
</Button>
<Button
style={styles}
onClick={() => handleSignIn('Microsoft')}
onClick={async () =>
await SignInMicrosoft().then((credentialUser) =>
redirect(credentialUser.user)
)
}
icon={<img src={microsoftLogo} alt="Logo da Microsoft." width="15px" />}
>
Microsoft
</Button>
<Button
style={styles}
onClick={() => handleSignIn('GitHub')}
onClick={async () =>
await SignInGitHub().then((credentialUser) =>
redirect(credentialUser.user)
)
}
icon={<img src={gitHubLogo} alt="Logo da GitHub." width="15px" />}
>
GitHub
Expand Down