Spaces:
Sleeping
Sleeping
Update app/auth/signup/page.tsx
Browse files- app/auth/signup/page.tsx +39 -15
app/auth/signup/page.tsx
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
import type React from "react"
|
4 |
|
5 |
-
import { useState } from "react"
|
6 |
import { motion } from "framer-motion"
|
7 |
import { Mail, Lock, Eye, EyeOff, ArrowRight, Sparkles, User } from "lucide-react"
|
8 |
import { Button } from "@/components/ui/button"
|
@@ -23,10 +23,20 @@ export default function SignupPage() {
|
|
23 |
const [error, setError] = useState("")
|
24 |
const router = useRouter()
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
27 |
setFormData({ ...formData, [e.target.name]: e.target.value })
|
28 |
}
|
29 |
|
|
|
30 |
const handleSignup = async (e: React.FormEvent) => {
|
31 |
e.preventDefault()
|
32 |
setIsLoading(true)
|
@@ -45,31 +55,45 @@ export default function SignupPage() {
|
|
45 |
}
|
46 |
|
47 |
try {
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
method: "POST",
|
50 |
-
|
51 |
-
|
52 |
-
name: formData.name,
|
53 |
-
email: formData.email,
|
54 |
-
password: formData.password,
|
55 |
-
}),
|
56 |
})
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
router.push("/")
|
63 |
} else {
|
64 |
-
|
|
|
65 |
}
|
66 |
} catch (error) {
|
|
|
67 |
setError("Network error. Please try again.")
|
68 |
} finally {
|
69 |
setIsLoading(false)
|
70 |
}
|
71 |
}
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
return (
|
74 |
<div className="min-h-screen bg-gradient-to-br from-purple-900 via-black to-pink-900 flex items-center justify-center p-4">
|
75 |
{/* Animated background elements */}
|
@@ -200,7 +224,7 @@ export default function SignupPage() {
|
|
200 |
|
201 |
<Button
|
202 |
type="button"
|
203 |
-
onClick={
|
204 |
className="w-full flex items-center justify-center gap-3 bg-white hover:bg-gray-100 text-gray-800 font-semibold py-3 rounded-xl transition-all duration-200"
|
205 |
>
|
206 |
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
|
|
|
2 |
|
3 |
import type React from "react"
|
4 |
|
5 |
+
import { useState, useEffect } from "react"
|
6 |
import { motion } from "framer-motion"
|
7 |
import { Mail, Lock, Eye, EyeOff, ArrowRight, Sparkles, User } from "lucide-react"
|
8 |
import { Button } from "@/components/ui/button"
|
|
|
23 |
const [error, setError] = useState("")
|
24 |
const router = useRouter()
|
25 |
|
26 |
+
// β
UPDATED: Handle URL errors from OAuth redirects
|
27 |
+
useEffect(() => {
|
28 |
+
const urlParams = new URLSearchParams(window.location.search)
|
29 |
+
const urlError = urlParams.get("error")
|
30 |
+
if (urlError) {
|
31 |
+
setError(decodeURIComponent(urlError))
|
32 |
+
}
|
33 |
+
}, [])
|
34 |
+
|
35 |
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
36 |
setFormData({ ...formData, [e.target.name]: e.target.value })
|
37 |
}
|
38 |
|
39 |
+
// β
UPDATED: Backend integration for signup
|
40 |
const handleSignup = async (e: React.FormEvent) => {
|
41 |
e.preventDefault()
|
42 |
setIsLoading(true)
|
|
|
55 |
}
|
56 |
|
57 |
try {
|
58 |
+
// β
FIXED: Use FormData for backend compatibility
|
59 |
+
const formDataToSend = new FormData()
|
60 |
+
formDataToSend.append('name', formData.name)
|
61 |
+
formDataToSend.append('email', formData.email)
|
62 |
+
formDataToSend.append('password', formData.password)
|
63 |
+
|
64 |
+
// β
FIXED: Call your actual backend endpoint
|
65 |
+
const response = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/auth/signup`, {
|
66 |
method: "POST",
|
67 |
+
body: formDataToSend,
|
68 |
+
credentials: 'include', // β
CRITICAL: Send cookies
|
|
|
|
|
|
|
|
|
69 |
})
|
70 |
|
71 |
+
if (response.ok) {
|
72 |
+
const data = await response.json()
|
73 |
+
console.log('β
Signup successful:', data)
|
74 |
+
router.push("/") // Redirect to home
|
|
|
75 |
} else {
|
76 |
+
const errorData = await response.json()
|
77 |
+
setError(errorData.detail || 'Signup failed')
|
78 |
}
|
79 |
} catch (error) {
|
80 |
+
console.error('β Signup error:', error)
|
81 |
setError("Network error. Please try again.")
|
82 |
} finally {
|
83 |
setIsLoading(false)
|
84 |
}
|
85 |
}
|
86 |
|
87 |
+
// β
UPDATED: Google OAuth with backend integration
|
88 |
+
const handleGoogleSignup = () => {
|
89 |
+
// Clear any existing Google session cookies
|
90 |
+
document.cookie = "G_AUTHUSER_H=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"
|
91 |
+
document.cookie = "G_ENABLED_IDPS=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"
|
92 |
+
|
93 |
+
// β
FIXED: Redirect to your backend Google OAuth endpoint
|
94 |
+
window.location.href = `${process.env.NEXT_PUBLIC_BACKEND_URL}/auth/google`
|
95 |
+
}
|
96 |
+
|
97 |
return (
|
98 |
<div className="min-h-screen bg-gradient-to-br from-purple-900 via-black to-pink-900 flex items-center justify-center p-4">
|
99 |
{/* Animated background elements */}
|
|
|
224 |
|
225 |
<Button
|
226 |
type="button"
|
227 |
+
onClick={handleGoogleSignup}
|
228 |
className="w-full flex items-center justify-center gap-3 bg-white hover:bg-gray-100 text-gray-800 font-semibold py-3 rounded-xl transition-all duration-200"
|
229 |
>
|
230 |
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
|