import type { RouterOutput } from "@/libs/orpc/client"; import { t } from "@lingui/core/macro"; import { Trans } from "@lingui/react/macro"; import { FingerprintIcon, GithubLogoIcon, GoogleLogoIcon, LinkedinLogoIcon, VaultIcon } from "@phosphor-icons/react"; import { useQuery } from "@tanstack/react-query"; import { useRouter } from "@tanstack/react-router"; import { toast } from "sonner"; import { Button } from "@reactive-resume/ui/components/button"; import { Skeleton } from "@reactive-resume/ui/components/skeleton"; import { cn } from "@reactive-resume/utils/style"; import { authClient } from "@/libs/auth/client"; import { orpc } from "@/libs/orpc/client"; type SocialAuthProps = { requestSignUp?: boolean; }; type SocialSignInOptions = { provider: string; callbackURL: string; requestSignUp?: true; }; function getSocialSignInOptions(provider: string, requestSignUp: boolean): SocialSignInOptions { const options: SocialSignInOptions = { provider, callbackURL: "/dashboard" }; if (requestSignUp) options.requestSignUp = true; return options; } export function SocialAuth({ requestSignUp = false }: SocialAuthProps) { const { data: providers = {}, isLoading } = useQuery(orpc.auth.providers.list.queryOptions()); return ( <>

or continue with
{isLoading ? : } ); } function SocialAuthSkeleton() { return (
); } type SocialAuthButtonsProps = { providers: RouterOutput["auth"]["providers"]["list"]; requestSignUp: boolean; }; function SocialAuthButtons({ providers, requestSignUp }: SocialAuthButtonsProps) { const router = useRouter(); const handleSocialLogin = async (provider: string) => { const toastId = toast.loading(t`Signing in...`); const { error } = await authClient.signIn.social(getSocialSignInOptions(provider, requestSignUp)); if (error) { toast.error( error.message || t({ comment: "Fallback toast when social sign-in fails without a provider error message", message: "Failed to sign in. Please try again.", }), { id: toastId }, ); return; } toast.dismiss(toastId); await router.invalidate(); }; const handleOAuthLogin = async () => { const toastId = toast.loading(t`Signing in...`); const { error } = await authClient.signIn.oauth2({ providerId: "custom", callbackURL: "/dashboard", }); if (error) { toast.error( error.message || t({ comment: "Fallback toast when custom OAuth sign-in fails without a provider error message", message: "Failed to sign in. Please try again.", }), { id: toastId }, ); return; } toast.dismiss(toastId); await router.invalidate(); }; const handlePasskeyLogin = async () => { const toastId = toast.loading(t`Signing in...`); const { error } = await authClient.signIn.passkey({ autoFill: false }); if (error) { toast.error( error.message || t({ comment: "Fallback toast when passkey sign-in fails without an error message", message: "Failed to sign in. Please try again.", }), { id: toastId }, ); return; } toast.dismiss(toastId); await router.invalidate(); }; return (
); }