Files
OpenStock/components/forms/SocialAuthButtons.tsx
ravixalgorithm 2f9385d4c6 feat(auth): Google/GitHub sign-in, working password reset, saved onboarding fields
- Better Auth handler at /api/auth (OAuth callbacks and reset links had no route).
- Reset emails double-encoded callbackURL (INVALID_CALLBACKURL); fixed with a test.
- Providers enable only when their env vars are set; documented in check-env.
- Session cookie cache and a per-request session helper; onboarding answers are
  stored on the user as additional fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 15:28:00 +05:30

63 lines
2.5 KiB
TypeScript

'use client';
import React, { useState } from "react";
import { Github } from "lucide-react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { signInWithSocial } from "@/lib/actions/auth.actions";
const GoogleIcon = () => (
<svg viewBox="0 0 24 24" aria-hidden="true" className="size-5">
<path fill="#4285F4" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.27-4.74 3.27-8.1z" />
<path fill="#34A853" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84A11 11 0 0 0 12 23z" />
<path fill="#FBBC05" d="M5.84 14.1a6.6 6.6 0 0 1 0-4.2V7.06H2.18a11 11 0 0 0 0 9.88l3.66-2.84z" />
<path fill="#EA4335" d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15A10.96 10.96 0 0 0 12 1 11 11 0 0 0 2.18 7.06l3.66 2.84C6.71 7.31 9.14 5.38 12 5.38z" />
</svg>
);
const PROVIDERS = [
{ id: 'google', label: 'Google', icon: <GoogleIcon /> },
{ id: 'github', label: 'GitHub', icon: <Github className="size-5" /> },
] as const;
const SocialAuthButtons = () => {
const [pending, setPending] = useState<string | null>(null);
const onClick = async (provider: 'google' | 'github') => {
setPending(provider);
const result = await signInWithSocial(provider);
if (result.success && result.url) {
window.location.href = result.url;
return;
}
setPending(null);
toast.error('Sign in failed', { description: result.error });
}
return (
<div className="space-y-5 mb-5">
<div className="grid grid-cols-2 gap-3">
{PROVIDERS.map(({ id, label, icon }) => (
<Button
key={id}
type="button"
variant="outline"
disabled={pending !== null}
onClick={() => onClick(id)}
className="h-12 border-gray-600 text-gray-400 text-base rounded-lg cursor-pointer"
>
{icon}
{pending === id ? 'Redirecting' : label}
</Button>
))}
</div>
<div className="flex items-center gap-3 text-sm text-gray-500">
<span className="h-px flex-1 bg-gray-600" />
or
<span className="h-px flex-1 bg-gray-600" />
</div>
</div>
);
};
export default SocialAuthButtons;