@lastbrain/module-auth 0.1.21 → 0.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/api/admin/signup-stats.d.ts +21 -0
  2. package/dist/api/admin/signup-stats.d.ts.map +1 -0
  3. package/dist/api/admin/signup-stats.js +75 -0
  4. package/dist/api/admin/users-by-source.d.ts +22 -0
  5. package/dist/api/admin/users-by-source.d.ts.map +1 -0
  6. package/dist/api/admin/users-by-source.js +56 -0
  7. package/dist/api/public/signup.d.ts +10 -0
  8. package/dist/api/public/signup.d.ts.map +1 -0
  9. package/dist/api/public/signup.js +71 -0
  10. package/dist/auth.build.config.d.ts.map +1 -1
  11. package/dist/auth.build.config.js +26 -0
  12. package/dist/index.d.ts +1 -0
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +1 -0
  15. package/dist/server.d.ts +1 -0
  16. package/dist/server.d.ts.map +1 -1
  17. package/dist/server.js +1 -0
  18. package/dist/web/admin/signup-stats.d.ts +2 -0
  19. package/dist/web/admin/signup-stats.d.ts.map +1 -0
  20. package/dist/web/admin/signup-stats.js +50 -0
  21. package/dist/web/admin/user-detail.d.ts.map +1 -1
  22. package/dist/web/admin/user-detail.js +5 -1
  23. package/dist/web/admin/users-by-signup-source.d.ts +2 -0
  24. package/dist/web/admin/users-by-signup-source.d.ts.map +1 -0
  25. package/dist/web/admin/users-by-signup-source.js +79 -0
  26. package/dist/web/auth/folder.d.ts.map +1 -1
  27. package/dist/web/auth/folder.js +3 -5
  28. package/dist/web/public/SignUpPage.d.ts.map +1 -1
  29. package/dist/web/public/SignUpPage.js +15 -23
  30. package/package.json +6 -6
  31. package/src/api/admin/signup-stats.ts +109 -0
  32. package/src/api/admin/users/[id]/notifications.ts +5 -5
  33. package/src/api/admin/users/[id].ts +5 -5
  34. package/src/api/admin/users-by-source.ts +87 -0
  35. package/src/api/admin/users.ts +4 -4
  36. package/src/api/auth/me.ts +1 -1
  37. package/src/api/auth/profile.ts +4 -4
  38. package/src/api/public/signup.ts +106 -0
  39. package/src/api/storage.ts +3 -3
  40. package/src/auth.build.config.ts +27 -0
  41. package/src/index.ts +1 -0
  42. package/src/server.ts +1 -0
  43. package/src/web/admin/signup-stats.tsx +304 -0
  44. package/src/web/admin/user-detail.tsx +19 -3
  45. package/src/web/admin/users-by-signup-source.tsx +262 -0
  46. package/src/web/admin/users.tsx +1 -1
  47. package/src/web/auth/dashboard.tsx +1 -1
  48. package/src/web/auth/folder.tsx +4 -14
  49. package/src/web/auth/profile.tsx +3 -3
  50. package/src/web/public/SignUpPage.tsx +17 -26
  51. package/supabase/migrations/20251112000000_user_init.sql +18 -1
  52. package/supabase/migrations/20251112000001_auto_profile_and_admin_view.sql +10 -2
  53. package/supabase/migrations/20251124000001_add_get_admin_user_details.sql +2 -1
  54. package/supabase/migrations-down/20251204000000_add_signup_source.sql +12 -0
@@ -146,19 +146,19 @@ export function ProfilePage() {
146
146
  "avatar",
147
147
  `${currentUser.id}_32_${version}.webp`,
148
148
  files.small,
149
- "image/webp",
149
+ "image/webp"
150
150
  );
151
151
  urls.medium = await uploadFile(
152
152
  "avatar",
153
153
  `${currentUser.id}_64_${version}.webp`,
154
154
  files.medium,
155
- "image/webp",
155
+ "image/webp"
156
156
  );
157
157
  urls.large = await uploadFile(
158
158
  "avatar",
159
159
  `${currentUser.id}_128_${version}.webp`,
160
160
  files.large,
161
- "image/webp",
161
+ "image/webp"
162
162
  );
163
163
 
164
164
  // Update user metadata
@@ -33,7 +33,7 @@ function SignUpForm() {
33
33
  const [success, setSuccess] = useState<string | null>(null);
34
34
 
35
35
  // Récupérer le paramètre redirect
36
- const redirectUrl = searchParams.get("redirect");
36
+ const redirectUrl = searchParams?.get("redirect") || "";
37
37
 
38
38
  const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
39
39
  event.preventDefault();
@@ -53,43 +53,34 @@ function SignUpForm() {
53
53
  setLoading(true);
54
54
 
55
55
  try {
56
- const { data, error: signUpError } =
57
- await supabaseBrowserClient.auth.signUp({
56
+ // Appeler la nouvelle route API signup (signupSource sera déterminé côté serveur via VERCEL_URL)
57
+ const response = await fetch("/api/auth/signup", {
58
+ method: "POST",
59
+ headers: {
60
+ "Content-Type": "application/json",
61
+ },
62
+ body: JSON.stringify({
58
63
  email,
59
64
  password,
60
- options: {
61
- emailRedirectTo: `${window.location.origin}/api/auth/callback${
62
- redirectUrl ? `?next=${encodeURIComponent(redirectUrl)}` : ""
63
- }`,
64
- data: {
65
- full_name: fullName,
66
- },
67
- },
68
- });
65
+ fullName,
66
+ }),
67
+ });
68
+
69
+ const result = await response.json();
69
70
 
70
- if (signUpError) {
71
- setError(signUpError.message);
71
+ if (!response.ok) {
72
+ setError(result.error || "Erreur lors de l'inscription");
72
73
  return;
73
74
  }
74
75
 
75
76
  // Si la confirmation par email est requise
76
- if (data.user && !data.session) {
77
+ if (result.data.user && !result.data.session) {
77
78
  setSuccess(
78
- "Compte créé avec succès ! Veuillez vérifier votre email pour confirmer votre compte.",
79
+ "Compte créé avec succès ! Veuillez vérifier votre email pour confirmer votre compte."
79
80
  );
80
81
  return;
81
82
  }
82
83
 
83
- // Si l'utilisateur est directement connecté (confirmation email désactivée)
84
- if (data.session) {
85
- if (redirectUrl) {
86
- window.location.href = redirectUrl;
87
- } else {
88
- window.location.href = "/auth/dashboard";
89
- }
90
- return;
91
- }
92
-
93
84
  setSuccess("Compte créé. Vous pouvez désormais vous connecter.");
94
85
  setTimeout(() => {
95
86
  if (redirectUrl) {
@@ -177,4 +177,21 @@ CREATE TRIGGER set_user_notifications_updated_at
177
177
  -- =====================================================
178
178
  -- Enable Realtime for user_notifications
179
179
  -- =====================================================
180
- ALTER PUBLICATION supabase_realtime ADD TABLE public.user_notifications;
180
+ ALTER PUBLICATION supabase_realtime ADD TABLE public.user_notifications;
181
+
182
+ -- Add signup_source to user_profil table
183
+ -- Track where users signed up from (e.g., 'lastbrain', 'recipe', etc.)
184
+
185
+ -- Add the column
186
+ ALTER TABLE public.user_profil
187
+ ADD COLUMN IF NOT EXISTS signup_source TEXT DEFAULT 'lastbrain';
188
+
189
+
190
+
191
+ -- Create an index for stats queries
192
+ CREATE INDEX IF NOT EXISTS idx_user_profil_signup_source
193
+ ON public.user_profil(signup_source);
194
+
195
+ -- Create an index for date range queries
196
+ CREATE INDEX IF NOT EXISTS idx_user_profil_created_at_source
197
+ ON public.user_profil(signup_source, created_at DESC);
@@ -19,9 +19,17 @@ END $$;
19
19
  -- Function to create user profile automatically
20
20
  CREATE OR REPLACE FUNCTION public.handle_new_user()
21
21
  RETURNS TRIGGER AS $$
22
+ DECLARE
23
+ signup_source_value TEXT;
22
24
  BEGIN
23
- INSERT INTO public.user_profil (owner_id, created_at, updated_at)
24
- VALUES (NEW.id, now(), now());
25
+ -- Extract signup_source from user metadata if present
26
+ signup_source_value := COALESCE(
27
+ NEW.raw_user_meta_data->>'signup_source',
28
+ 'lastbrain'
29
+ );
30
+
31
+ INSERT INTO public.user_profil (owner_id, signup_source, created_at, updated_at)
32
+ VALUES (NEW.id, signup_source_value, now(), now());
25
33
  RETURN NEW;
26
34
  EXCEPTION
27
35
  WHEN unique_violation THEN
@@ -47,7 +47,8 @@ BEGIN
47
47
  'preferences', p.preferences,
48
48
  'avatar_url', p.avatar_url,
49
49
  'created_at', p.created_at,
50
- 'updated_at', p.updated_at
50
+ 'updated_at', p.updated_at,
51
+ 'signup_source', p.signup_source
51
52
  )
52
53
  ) INTO result
53
54
  FROM public.user_profil p
@@ -0,0 +1,12 @@
1
+ -- Rollback: Remove signup_source from user_profil table
2
+
3
+ -- Drop indexes
4
+ DROP INDEX IF EXISTS public.idx_user_profil_created_at_source;
5
+ DROP INDEX IF EXISTS public.idx_user_profil_signup_source;
6
+
7
+ -- Drop constraint and column
8
+ ALTER TABLE public.user_profil
9
+ DROP CONSTRAINT IF EXISTS user_profil_signup_source_check;
10
+
11
+ ALTER TABLE public.user_profil
12
+ DROP COLUMN IF EXISTS signup_source;