vaibhav07112004 commited on
Commit
de616aa
Β·
verified Β·
1 Parent(s): 214b8ea

Update app/auth/signup/page.tsx

Browse files
Files changed (1) hide show
  1. 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
- const response = await fetch("/api/auth/signup", {
 
 
 
 
 
 
 
49
  method: "POST",
50
- headers: { "Content-Type": "application/json" },
51
- body: JSON.stringify({
52
- name: formData.name,
53
- email: formData.email,
54
- password: formData.password,
55
- }),
56
  })
57
 
58
- const data = await response.json()
59
-
60
- if (data.success) {
61
- localStorage.setItem("user", JSON.stringify(data.user))
62
- router.push("/")
63
  } else {
64
- setError(data.error || "Signup failed")
 
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={() => (window.location.href = "/api/auth/google")}
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">