Remove social auth and stabilize email/password flow
This commit is contained in:
@@ -1,15 +1,25 @@
|
||||
'use client';
|
||||
|
||||
import { signUp } from '@/lib/better-auth';
|
||||
import { useState } from 'react';
|
||||
import { signUp, useSession } from '@/lib/better-auth';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export default function SignUp() {
|
||||
const { data: session, isPending: sessionPending } = useSession();
|
||||
const router = useRouter();
|
||||
|
||||
const [name, setName] = useState('');
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
if (!sessionPending && session?.user) {
|
||||
router.replace('/');
|
||||
}
|
||||
}, [sessionPending, session, router]);
|
||||
|
||||
const handleSignUp = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
@@ -25,7 +35,8 @@ export default function SignUp() {
|
||||
if (result.error) {
|
||||
setError(result.error.message || 'Sign up failed');
|
||||
} else {
|
||||
window.location.href = '/';
|
||||
router.replace('/');
|
||||
router.refresh();
|
||||
}
|
||||
} catch (err) {
|
||||
setError('Sign up failed');
|
||||
@@ -94,7 +105,7 @@ export default function SignUp() {
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
disabled={loading || sessionPending}
|
||||
className="w-full bg-gradient-to-r from-blue-500 to-purple-500 hover:from-blue-600 hover:to-purple-600 text-white font-semibold py-3 rounded-lg transition disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
{loading ? 'Creating account...' : 'Sign Up'}
|
||||
|
||||
Reference in New Issue
Block a user