import { observer } from "mobx-react-lite"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; // services import { AuthService } from "services/auth.service"; import { UserService } from "services/user.service"; // hooks import useToast from "hooks/use-toast"; // components import { ESignInSteps, GithubLoginButton, GoogleLoginButton } from "components/account"; type Props = { updateEmail: (email: string) => void; handleStepChange: (step: ESignInSteps) => void; handleSignInRedirection: () => Promise; }; // services const authService = new AuthService(); const userService = new UserService(); export const OAuthOptions: React.FC = observer((props) => { const { updateEmail, handleStepChange, handleSignInRedirection } = props; // toast alert const { setToastAlert } = useToast(); // mobx store const { appConfig: { envConfig }, } = useMobxStore(); const handleGoogleSignIn = async ({ clientId, credential }: any) => { try { if (clientId && credential) { const socialAuthPayload = { medium: "google", credential, clientId, }; const response = await authService.socialAuth(socialAuthPayload); if (response) { const currentUser = await userService.currentUser(); updateEmail(currentUser.email); if (currentUser.is_password_autoset) handleStepChange(ESignInSteps.OPTIONAL_SET_PASSWORD); else handleSignInRedirection(); } } else throw Error("Cant find credentials"); } catch (err: any) { setToastAlert({ title: "Error signing in!", type: "error", message: err?.error || "Something went wrong. Please try again later or contact the support team.", }); } }; const handleGitHubSignIn = async (credential: string) => { try { if (envConfig && envConfig.github_client_id && credential) { const socialAuthPayload = { medium: "github", credential, clientId: envConfig.github_client_id, }; const response = await authService.socialAuth(socialAuthPayload); if (response) { const currentUser = await userService.currentUser(); updateEmail(currentUser.email); if (currentUser.is_password_autoset) handleStepChange(ESignInSteps.OPTIONAL_SET_PASSWORD); else handleSignInRedirection(); } } else throw Error("Cant find credentials"); } catch (err: any) { setToastAlert({ title: "Error signing in!", type: "error", message: err?.error || "Something went wrong. Please try again later or contact the support team.", }); } }; return ( <>

Or continue with


{envConfig?.google_client_id && ( )} {envConfig?.github_client_id && ( )}
); });