-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
changes.patch
180 lines (169 loc) · 5.49 KB
/
changes.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
From 33fe5c02b724b9e1ebd6e4cecaba52882a5bd8fb Mon Sep 17 00:00:00 2001
From: bbarclay <barclaybrandon@hotmail.com>
Date: Wed, 9 Oct 2024 14:58:53 -0600
Subject: [PATCH] fix registration
---
frontend/src/contexts/AuthContext.tsx | 109 +++++++-------------------
vercel.json | 8 +-
2 files changed, 36 insertions(+), 81 deletions(-)
diff --git a/frontend/src/contexts/AuthContext.tsx b/frontend/src/contexts/AuthContext.tsx
index 7584881..1d30bf1 100644
--- a/frontend/src/contexts/AuthContext.tsx
+++ b/frontend/src/contexts/AuthContext.tsx
@@ -1,5 +1,4 @@
import React, { createContext, useState, useContext, useEffect, ReactNode } from 'react';
-import { supabase } from '../lib/supabaseClient';
import { User, Session, Provider } from '@supabase/supabase-js';
interface AuthContextType {
@@ -19,97 +18,50 @@ export function AuthProvider({ children }: { children: ReactNode }) {
const [isAuthenticated, setIsAuthenticated] = useState(false);
useEffect(() => {
- const fetchSession = async () => {
- const { data: { session } } = await supabase.auth.getSession();
- setUser(session?.user ?? null);
- setIsAuthenticated(!!session?.user);
- };
-
- fetchSession();
-
- const { data: authListener } = supabase.auth.onAuthStateChange(
- (_event: string, session: Session | null) => {
- setUser(session?.user ?? null);
- setIsAuthenticated(!!session?.user);
- }
- );
-
- return () => {
- authListener.subscription.unsubscribe();
- };
+ // Check for existing session (you may need to implement this)
}, []);
const login = async (email: string, password: string) => {
- const { error } = await supabase.auth.signInWithPassword({ email, password });
- if (error) throw error;
+ const response = await fetch('/auth/v1/login', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ email, password }),
+ });
+ if (!response.ok) throw new Error('Login failed');
+ const data = await response.json();
+ setUser(data.user);
+ setIsAuthenticated(true);
};
const logout = async () => {
- const { error } = await supabase.auth.signOut();
- if (error) throw error;
+ await fetch('/auth/v1/logout', { method: 'POST' });
+ setUser(null);
+ setIsAuthenticated(false);
};
-const register = async (email: string, password: string, firstName: string, lastName: string) => {
- console.log('Starting registration process', { email, firstName, lastName });
- try {
- const { data, error } = await supabase.auth.signUp({
- email,
- password,
- options: {
- data: {
- first_name: firstName,
- last_name: lastName,
- },
- },
- });
- if (error) {
- console.error('Registration error:', error);
- throw error;
- }
-
- console.log('Registration successful:', data);
-
- if (data && data.user) {
- console.log('Creating user profile');
- const { error: profileError } = await supabase
- .from('users')
- .insert([
- {
- id: data.user.id,
- email: email,
- first_name: firstName,
- last_name: lastName,
- },
- ]);
-
- if (profileError) {
- console.error('Profile creation error:', profileError);
- throw profileError;
- }
-
- console.log('Profile created successfully');
-
- // Automatically log in the user after successful registration
- console.log('Attempting automatic login');
- await login(email, password);
- console.log('Automatic login successful');
- } else {
- console.error('User data not available after registration');
- }
- } catch (error) {
- console.error('Unexpected error during registration:', error);
- throw error;
- }
+ const register = async (email: string, password: string, firstName: string, lastName: string) => {
+ const response = await fetch('/auth/v1/register', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ email, password, firstName, lastName }),
+ });
+ if (!response.ok) throw new Error('Registration failed');
+ const data = await response.json();
+ setUser(data.user);
+ setIsAuthenticated(true);
};
const resetPassword = async (email: string) => {
- const { error } = await supabase.auth.resetPasswordForEmail(email);
- if (error) throw error;
+ const response = await fetch('/auth/v1/password-reset', {
+ method: 'PUT',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ email }),
+ });
+ if (!response.ok) throw new Error('Password reset failed');
};
const socialLogin = async (provider: Provider) => {
- const { error } = await supabase.auth.signInWithOAuth({ provider });
- if (error) throw error;
+ // Implement social login if needed
};
return (
@@ -126,4 +78,3 @@ export function useAuth() {
}
return context;
}
-
diff --git a/vercel.json b/vercel.json
index 309b1da..d04cde8 100644
--- a/vercel.json
+++ b/vercel.json
@@ -14,13 +14,17 @@
}
],
"routes": [
+ {
+ "src": "/auth/v1/(.*)",
+ "dest": "backend/api/src/auth/"
+ },
{
"src": "/api/(.*)",
- "dest": "backend/api/$1"
+ "dest": "backend/api/"
},
{
"src": "/(.*)",
- "dest": "frontend/$1"
+ "dest": "frontend/"
}
]
}
--
2.39.5