@digilogiclabs/create-saas-app 1.5.2 → 1.5.3
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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/templates/mobile/base/template/.env.example +15 -0
- package/dist/templates/mobile/base/template/App.tsx +88 -0
- package/dist/templates/mobile/base/template/app/(auth)/login.tsx +44 -0
- package/dist/templates/mobile/base/template/app/(auth)/signup.tsx +43 -0
- package/dist/templates/mobile/base/template/app/checkout.tsx +20 -0
- package/dist/templates/mobile/base/template/package.json +38 -0
- package/dist/templates/shared/auth/firebase/web/config.ts +23 -0
- package/dist/templates/shared/auth/supabase/web/config.ts +8 -0
- package/dist/templates/web/base/template/.env.example +15 -0
- package/dist/templates/web/base/template/.eslintrc.js +8 -0
- package/dist/templates/web/base/template/README.md +68 -0
- package/dist/templates/web/base/template/next.config.js +15 -0
- package/dist/templates/web/base/template/package.json +58 -0
- package/dist/templates/web/base/template/postcss.config.js +7 -0
- package/dist/templates/web/base/template/src/app/auth/callback/route.ts +18 -0
- package/dist/templates/web/base/template/src/app/checkout/page.tsx +28 -0
- package/dist/templates/web/base/template/src/app/error.tsx +97 -0
- package/dist/templates/web/base/template/src/app/globals.css +60 -0
- package/dist/templates/web/base/template/src/app/layout.tsx +35 -0
- package/dist/templates/web/base/template/src/app/loading.tsx +34 -0
- package/dist/templates/web/base/template/src/app/login/page.tsx +39 -0
- package/dist/templates/web/base/template/src/app/page.tsx +132 -0
- package/dist/templates/web/base/template/src/app/signup/page.tsx +39 -0
- package/dist/templates/web/base/template/src/components/__tests__/example.test.tsx +49 -0
- package/dist/templates/web/base/template/src/components/providers/app-providers.tsx +33 -0
- package/dist/templates/web/base/template/src/components/providers/theme-provider.tsx +94 -0
- package/dist/templates/web/base/template/src/components/shared/footer.tsx +36 -0
- package/dist/templates/web/base/template/src/components/shared/header.tsx +44 -0
- package/dist/templates/web/base/template/src/components/ui/badge.tsx +36 -0
- package/dist/templates/web/base/template/src/components/ui/button.tsx +56 -0
- package/dist/templates/web/base/template/src/components/ui/card.tsx +71 -0
- package/dist/templates/web/base/template/src/components/ui/theme-toggle.tsx +34 -0
- package/dist/templates/web/base/template/src/lib/auth-server.ts +177 -0
- package/dist/templates/web/base/template/src/lib/env.ts +46 -0
- package/dist/templates/web/base/template/src/lib/utils.ts +140 -0
- package/dist/templates/web/base/template/src/test/setup.ts +79 -0
- package/dist/templates/web/base/template/tailwind.config.js +77 -0
- package/dist/templates/web/base/template/tsconfig.json +33 -0
- package/dist/templates/web/base/template/vitest.config.ts +17 -0
- package/dist/templates/web/base/template.backup/.env.example +15 -0
- package/dist/templates/web/base/template.backup.20250817/.env.example +15 -0
- package/dist/templates/web/ui-auth/template/.env.example +15 -0
- package/dist/templates/web/ui-auth/template/.eslintrc.js +8 -0
- package/dist/templates/web/ui-auth/template/README.md +68 -0
- package/dist/templates/web/ui-auth/template/next.config.js +12 -0
- package/dist/templates/web/ui-auth/template/package.json +50 -0
- package/dist/templates/web/ui-auth/template/postcss.config.js +7 -0
- package/dist/templates/web/ui-auth/template/src/app/auth/callback/route.ts +12 -0
- package/dist/templates/web/ui-auth/template/src/app/checkout/page.tsx +25 -0
- package/dist/templates/web/ui-auth/template/src/app/error.tsx +67 -0
- package/dist/templates/web/ui-auth/template/src/app/globals.css +42 -0
- package/dist/templates/web/ui-auth/template/src/app/layout.tsx +33 -0
- package/dist/templates/web/ui-auth/template/src/app/loading.tsx +20 -0
- package/dist/templates/web/ui-auth/template/src/app/login/page.tsx +109 -0
- package/dist/templates/web/ui-auth/template/src/app/page.tsx +129 -0
- package/dist/templates/web/ui-auth/template/src/app/signup/page.tsx +128 -0
- package/dist/templates/web/ui-auth/template/src/components/__tests__/example.test.tsx +49 -0
- package/dist/templates/web/ui-auth/template/src/components/providers/app-providers.tsx +29 -0
- package/dist/templates/web/ui-auth/template/src/components/providers/theme-provider.tsx +94 -0
- package/dist/templates/web/ui-auth/template/src/components/shared/footer.tsx +36 -0
- package/dist/templates/web/ui-auth/template/src/components/shared/header.tsx +53 -0
- package/dist/templates/web/ui-auth/template/src/components/ui/badge.tsx +36 -0
- package/dist/templates/web/ui-auth/template/src/components/ui/theme-toggle.tsx +34 -0
- package/dist/templates/web/ui-auth/template/src/lib/env.ts +49 -0
- package/dist/templates/web/ui-auth/template/src/lib/utils.ts +140 -0
- package/dist/templates/web/ui-auth/template/src/test/setup.ts +79 -0
- package/dist/templates/web/ui-auth/template/tailwind.config.js +77 -0
- package/dist/templates/web/ui-auth/template/tsconfig.json +33 -0
- package/dist/templates/web/ui-auth/template/vitest.config.ts +17 -0
- package/dist/templates/web/ui-auth/template.backup/.env.example +15 -0
- package/dist/templates/web/ui-auth/template.backup.20250817/.env.example +15 -0
- package/dist/templates/web/ui-auth-payments/template/.env.example +15 -0
- package/dist/templates/web/ui-auth-payments/template/README.md +165 -0
- package/dist/templates/web/ui-auth-payments/template/middleware.ts +68 -0
- package/dist/templates/web/ui-auth-payments/template/next.config.js +12 -0
- package/dist/templates/web/ui-auth-payments/template/package-lock.json +12240 -0
- package/dist/templates/web/ui-auth-payments/template/package.json +52 -0
- package/dist/templates/web/ui-auth-payments/template/postcss.config.js +7 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/auth/callback/route.ts +12 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/billing/page.tsx +211 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/checkout/page.tsx +142 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/dashboard/layout.tsx +22 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/dashboard/page.tsx +183 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/error.tsx +67 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/globals.css +42 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/layout.tsx +33 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/loading.tsx +20 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/login/loading.tsx +38 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/login/page.tsx +109 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/page.tsx +143 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/signup/loading.tsx +50 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/signup/page.tsx +128 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/__tests__/example.test.tsx +49 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/client/auth-status.tsx +52 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/client/login-form.tsx +144 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/client/newsletter-signup.tsx +68 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/client/signup-form.tsx +185 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/providers/app-providers.tsx +32 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/providers/theme-provider.tsx +94 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/shared/footer.tsx +36 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/shared/header.tsx +62 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/ui/badge.tsx +36 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/ui/theme-toggle.tsx +34 -0
- package/dist/templates/web/ui-auth-payments/template/src/lib/actions/auth.ts +246 -0
- package/dist/templates/web/ui-auth-payments/template/src/lib/actions/index.ts +340 -0
- package/dist/templates/web/ui-auth-payments/template/src/lib/auth-server.ts +177 -0
- package/dist/templates/web/ui-auth-payments/template/src/lib/env.ts +49 -0
- package/dist/templates/web/ui-auth-payments/template/src/lib/utils.ts +140 -0
- package/dist/templates/web/ui-auth-payments/template/src/test/setup.ts +79 -0
- package/dist/templates/web/ui-auth-payments/template/tailwind.config.js +77 -0
- package/dist/templates/web/ui-auth-payments/template/tsconfig.json +33 -0
- package/dist/templates/web/ui-auth-payments/template/tsconfig.tsbuildinfo +1 -0
- package/dist/templates/web/ui-auth-payments/template/vitest.config.ts +17 -0
- package/dist/templates/web/ui-auth-payments-audio/template/.env.example +15 -0
- package/dist/templates/web/ui-auth-payments-audio/template/README.md +187 -0
- package/dist/templates/web/ui-auth-payments-audio/template/middleware.ts +68 -0
- package/dist/templates/web/ui-auth-payments-audio/template/next.config.js +12 -0
- package/dist/templates/web/ui-auth-payments-audio/template/package-lock.json +12241 -0
- package/dist/templates/web/ui-auth-payments-audio/template/package.json +53 -0
- package/dist/templates/web/ui-auth-payments-audio/template/postcss.config.js +7 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/auth/callback/route.ts +12 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/billing/page.tsx +211 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/checkout/page.tsx +142 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/dashboard/layout.tsx +22 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/dashboard/page.tsx +183 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/error.tsx +67 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/globals.css +42 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/layout.tsx +35 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/loading.tsx +20 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/login/page.tsx +6 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/page.tsx +181 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/signup/page.tsx +6 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/__tests__/example.test.tsx +49 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/client/auth-status.tsx +52 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/client/login-form.tsx +144 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/client/signup-form.tsx +185 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/providers/app-providers.tsx +32 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/providers/theme-provider.tsx +94 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/shared/footer.tsx +36 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/shared/header.tsx +62 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/ui/badge.tsx +36 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/ui/theme-toggle.tsx +34 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/lib/actions/auth.ts +246 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/lib/actions/index.ts +14 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/lib/auth-server.ts +177 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/lib/env.ts +49 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/lib/utils.ts +140 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/test/setup.ts +79 -0
- package/dist/templates/web/ui-auth-payments-audio/template/tailwind.config.js +77 -0
- package/dist/templates/web/ui-auth-payments-audio/template/tsconfig.json +33 -0
- package/dist/templates/web/ui-auth-payments-audio/template/tsconfig.tsbuildinfo +1 -0
- package/dist/templates/web/ui-auth-payments-audio/template/vitest.config.ts +17 -0
- package/dist/templates/web/ui-auth-payments-video/template/.env.example +15 -0
- package/dist/templates/web/ui-auth-payments-video/template/README.md +190 -0
- package/dist/templates/web/ui-auth-payments-video/template/next.config.js +12 -0
- package/dist/templates/web/ui-auth-payments-video/template/package.json +53 -0
- package/dist/templates/web/ui-auth-payments-video/template/postcss.config.js +7 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/auth/callback/route.ts +12 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/billing/page.tsx +211 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/checkout/page.tsx +142 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/error.tsx +67 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/globals.css +42 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/layout.tsx +33 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/loading.tsx +20 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/login/page.tsx +109 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/page.tsx +187 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/signup/page.tsx +128 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/components/__tests__/example.test.tsx +49 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/components/providers/app-providers.tsx +32 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/components/providers/theme-provider.tsx +94 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/components/shared/footer.tsx +36 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/components/shared/header.tsx +62 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/components/ui/badge.tsx +36 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/components/ui/theme-toggle.tsx +34 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/lib/env.ts +49 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/lib/utils.ts +140 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/test/setup.ts +79 -0
- package/dist/templates/web/ui-auth-payments-video/template/tailwind.config.js +77 -0
- package/dist/templates/web/ui-auth-payments-video/template/tsconfig.json +33 -0
- package/dist/templates/web/ui-auth-payments-video/template/vitest.config.ts +17 -0
- package/dist/templates/web/ui-only/template/.env.example +15 -0
- package/dist/templates/web/ui-only/template/.eslintrc.js +8 -0
- package/dist/templates/web/ui-only/template/README.md +68 -0
- package/dist/templates/web/ui-only/template/next.config.js +12 -0
- package/dist/templates/web/ui-only/template/package.json +49 -0
- package/dist/templates/web/ui-only/template/postcss.config.js +7 -0
- package/dist/templates/web/ui-only/template/src/app/auth/callback/route.ts +12 -0
- package/dist/templates/web/ui-only/template/src/app/checkout/page.tsx +25 -0
- package/dist/templates/web/ui-only/template/src/app/error.tsx +67 -0
- package/dist/templates/web/ui-only/template/src/app/globals.css +42 -0
- package/dist/templates/web/ui-only/template/src/app/layout.tsx +33 -0
- package/dist/templates/web/ui-only/template/src/app/loading.tsx +20 -0
- package/dist/templates/web/ui-only/template/src/app/login/page.tsx +63 -0
- package/dist/templates/web/ui-only/template/src/app/page.tsx +91 -0
- package/dist/templates/web/ui-only/template/src/app/signup/page.tsx +79 -0
- package/dist/templates/web/ui-only/template/src/components/__tests__/example.test.tsx +49 -0
- package/dist/templates/web/ui-only/template/src/components/providers/app-providers.tsx +26 -0
- package/dist/templates/web/ui-only/template/src/components/providers/theme-provider.tsx +94 -0
- package/dist/templates/web/ui-only/template/src/components/shared/footer.tsx +36 -0
- package/dist/templates/web/ui-only/template/src/components/shared/header.tsx +53 -0
- package/dist/templates/web/ui-only/template/src/components/ui/badge.tsx +36 -0
- package/dist/templates/web/ui-only/template/src/components/ui/theme-toggle.tsx +34 -0
- package/dist/templates/web/ui-only/template/src/lib/env.ts +49 -0
- package/dist/templates/web/ui-only/template/src/lib/utils.ts +140 -0
- package/dist/templates/web/ui-only/template/src/test/setup.ts +79 -0
- package/dist/templates/web/ui-only/template/tailwind.config.js +77 -0
- package/dist/templates/web/ui-only/template/tsconfig.json +33 -0
- package/dist/templates/web/ui-only/template/vitest.config.ts +17 -0
- package/dist/templates/web/ui-only/template.backup/.env.example +15 -0
- package/dist/templates/web/ui-only/template.backup.20250817/.env.example +15 -0
- package/dist/templates/web/ui-package-test/template/next-env.d.ts +5 -0
- package/dist/templates/web/ui-package-test/template/package.json +42 -0
- package/dist/templates/web/ui-package-test/template/src/app/page.tsx +106 -0
- package/dist/templates/web/ui-package-test/template/tsconfig.json +41 -0
- package/package.json +3 -2
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
'use server'
|
|
2
|
+
|
|
3
|
+
import { redirect } from 'next/navigation'
|
|
4
|
+
import { cookies } from 'next/headers'
|
|
5
|
+
import { z } from 'zod'
|
|
6
|
+
|
|
7
|
+
// Schema for form validation
|
|
8
|
+
const signInSchema = z.object({
|
|
9
|
+
email: z.string().email('Invalid email address'),
|
|
10
|
+
password: z.string().min(6, 'Password must be at least 6 characters'),
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const signUpSchema = z.object({
|
|
14
|
+
email: z.string().email('Invalid email address'),
|
|
15
|
+
password: z.string().min(6, 'Password must be at least 6 characters'),
|
|
16
|
+
confirmPassword: z.string(),
|
|
17
|
+
name: z.string().min(2, 'Name must be at least 2 characters').optional(),
|
|
18
|
+
}).refine((data) => data.password === data.confirmPassword, {
|
|
19
|
+
message: "Passwords don't match",
|
|
20
|
+
path: ["confirmPassword"],
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
// Response types
|
|
24
|
+
type ActionResult = {
|
|
25
|
+
success: boolean
|
|
26
|
+
error?: string
|
|
27
|
+
fieldErrors?: Record<string, string[]>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Server action for signing in
|
|
32
|
+
* This works alongside the client-side @digilogiclabs/saas-factory-auth
|
|
33
|
+
*/
|
|
34
|
+
export async function signInAction(prevState: any, formData: FormData): Promise<ActionResult> {
|
|
35
|
+
try {
|
|
36
|
+
const rawData = {
|
|
37
|
+
email: formData.get('email') as string,
|
|
38
|
+
password: formData.get('password') as string,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Validate form data
|
|
42
|
+
const validationResult = signInSchema.safeParse(rawData)
|
|
43
|
+
|
|
44
|
+
if (!validationResult.success) {
|
|
45
|
+
return {
|
|
46
|
+
success: false,
|
|
47
|
+
error: 'Please check your input',
|
|
48
|
+
fieldErrors: validationResult.error.formErrors.fieldErrors,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const { email, password } = validationResult.data
|
|
53
|
+
|
|
54
|
+
// Note: The actual authentication is handled by the client-side library
|
|
55
|
+
// This server action is mainly for form validation and server-side processing
|
|
56
|
+
// You might want to add additional server-side logic here like:
|
|
57
|
+
// - Rate limiting
|
|
58
|
+
// - Logging
|
|
59
|
+
// - Analytics
|
|
60
|
+
|
|
61
|
+
// For now, we'll return success and let the client handle the actual auth
|
|
62
|
+
return {
|
|
63
|
+
success: true,
|
|
64
|
+
}
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error('Sign in error:', error)
|
|
67
|
+
return {
|
|
68
|
+
success: false,
|
|
69
|
+
error: 'An unexpected error occurred. Please try again.',
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Server action for signing up
|
|
76
|
+
*/
|
|
77
|
+
export async function signUpAction(prevState: any, formData: FormData): Promise<ActionResult> {
|
|
78
|
+
try {
|
|
79
|
+
const rawData = {
|
|
80
|
+
email: formData.get('email') as string,
|
|
81
|
+
password: formData.get('password') as string,
|
|
82
|
+
confirmPassword: formData.get('confirmPassword') as string,
|
|
83
|
+
name: formData.get('name') as string,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Validate form data
|
|
87
|
+
const validationResult = signUpSchema.safeParse(rawData)
|
|
88
|
+
|
|
89
|
+
if (!validationResult.success) {
|
|
90
|
+
return {
|
|
91
|
+
success: false,
|
|
92
|
+
error: 'Please check your input',
|
|
93
|
+
fieldErrors: validationResult.error.formErrors.fieldErrors,
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const { email, password, name } = validationResult.data
|
|
98
|
+
|
|
99
|
+
// Additional server-side processing can go here
|
|
100
|
+
// - User existence check
|
|
101
|
+
// - Welcome email preparation
|
|
102
|
+
// - User analytics setup
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
success: true,
|
|
106
|
+
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error('Sign up error:', error)
|
|
109
|
+
return {
|
|
110
|
+
success: false,
|
|
111
|
+
error: 'An unexpected error occurred. Please try again.',
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Server action for signing out
|
|
118
|
+
*/
|
|
119
|
+
export async function signOutAction(): Promise<void> {
|
|
120
|
+
try {
|
|
121
|
+
const cookieStore = await cookies()
|
|
122
|
+
|
|
123
|
+
// Clear auth cookies (adjust cookie names based on the auth library)
|
|
124
|
+
cookieStore.delete('saas-factory-auth-token')
|
|
125
|
+
cookieStore.delete('saas-factory-auth-user')
|
|
126
|
+
|
|
127
|
+
// Additional cleanup can go here
|
|
128
|
+
// - Clear session data
|
|
129
|
+
// - Log sign out event
|
|
130
|
+
// - Clear cache
|
|
131
|
+
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.error('Sign out error:', error)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
redirect('/')
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Server action for OAuth redirect handling
|
|
141
|
+
*/
|
|
142
|
+
export async function handleOAuthCallback(provider: string, code: string): Promise<ActionResult> {
|
|
143
|
+
try {
|
|
144
|
+
// This would handle OAuth callback processing
|
|
145
|
+
// For now, we'll delegate to the client-side library
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
success: true,
|
|
149
|
+
}
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.error('OAuth callback error:', error)
|
|
152
|
+
return {
|
|
153
|
+
success: false,
|
|
154
|
+
error: 'Authentication failed. Please try again.',
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Server action for password reset request
|
|
161
|
+
*/
|
|
162
|
+
export async function requestPasswordReset(prevState: any, formData: FormData): Promise<ActionResult> {
|
|
163
|
+
try {
|
|
164
|
+
const email = formData.get('email') as string
|
|
165
|
+
|
|
166
|
+
if (!email) {
|
|
167
|
+
return {
|
|
168
|
+
success: false,
|
|
169
|
+
error: 'Email is required',
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const emailSchema = z.string().email()
|
|
174
|
+
const validationResult = emailSchema.safeParse(email)
|
|
175
|
+
|
|
176
|
+
if (!validationResult.success) {
|
|
177
|
+
return {
|
|
178
|
+
success: false,
|
|
179
|
+
error: 'Please enter a valid email address',
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Password reset logic would go here
|
|
184
|
+
// - Generate reset token
|
|
185
|
+
// - Send reset email
|
|
186
|
+
// - Log reset request
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
success: true,
|
|
190
|
+
}
|
|
191
|
+
} catch (error) {
|
|
192
|
+
console.error('Password reset error:', error)
|
|
193
|
+
return {
|
|
194
|
+
success: false,
|
|
195
|
+
error: 'An unexpected error occurred. Please try again.',
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Server action for updating user profile
|
|
202
|
+
*/
|
|
203
|
+
export async function updateProfileAction(prevState: any, formData: FormData): Promise<ActionResult> {
|
|
204
|
+
try {
|
|
205
|
+
// This would require authentication check
|
|
206
|
+
const cookieStore = await cookies()
|
|
207
|
+
const authToken = cookieStore.get('saas-factory-auth-token')?.value
|
|
208
|
+
|
|
209
|
+
if (!authToken) {
|
|
210
|
+
redirect('/login')
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const name = formData.get('name') as string
|
|
214
|
+
const email = formData.get('email') as string
|
|
215
|
+
|
|
216
|
+
const updateSchema = z.object({
|
|
217
|
+
name: z.string().min(2, 'Name must be at least 2 characters').optional(),
|
|
218
|
+
email: z.string().email('Invalid email address').optional(),
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
const validationResult = updateSchema.safeParse({ name, email })
|
|
222
|
+
|
|
223
|
+
if (!validationResult.success) {
|
|
224
|
+
return {
|
|
225
|
+
success: false,
|
|
226
|
+
error: 'Please check your input',
|
|
227
|
+
fieldErrors: validationResult.error.formErrors.fieldErrors,
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Profile update logic would go here
|
|
232
|
+
// - Update user in database
|
|
233
|
+
// - Update auth cookies
|
|
234
|
+
// - Send confirmation email if email changed
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
success: true,
|
|
238
|
+
}
|
|
239
|
+
} catch (error) {
|
|
240
|
+
console.error('Profile update error:', error)
|
|
241
|
+
return {
|
|
242
|
+
success: false,
|
|
243
|
+
error: 'An unexpected error occurred. Please try again.',
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Re-export all server actions for easier imports
|
|
2
|
+
export {
|
|
3
|
+
signInAction,
|
|
4
|
+
signUpAction,
|
|
5
|
+
signOutAction,
|
|
6
|
+
handleOAuthCallback,
|
|
7
|
+
requestPasswordReset,
|
|
8
|
+
updateProfileAction,
|
|
9
|
+
} from './auth'
|
|
10
|
+
|
|
11
|
+
// Add other action exports here as needed
|
|
12
|
+
// export * from './posts'
|
|
13
|
+
// export * from './profile'
|
|
14
|
+
// export * from './settings'
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { cookies } from 'next/headers'
|
|
2
|
+
import { redirect } from 'next/navigation'
|
|
3
|
+
|
|
4
|
+
// Server-side auth utilities that work with @digilogiclabs/saas-factory-auth
|
|
5
|
+
// These functions provide server-side access to auth state
|
|
6
|
+
|
|
7
|
+
export type User = {
|
|
8
|
+
id: string
|
|
9
|
+
email: string
|
|
10
|
+
name?: string
|
|
11
|
+
avatar?: string
|
|
12
|
+
[key: string]: any
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Get the current user from server-side cookies
|
|
17
|
+
* This function should be called in Server Components, Server Actions, or Route Handlers
|
|
18
|
+
*/
|
|
19
|
+
export async function getCurrentUser(): Promise<User | null> {
|
|
20
|
+
try {
|
|
21
|
+
const cookieStore = await cookies()
|
|
22
|
+
|
|
23
|
+
// Check for auth token in cookies set by @digilogiclabs/saas-factory-auth
|
|
24
|
+
const authToken = cookieStore.get('saas-factory-auth-token')?.value
|
|
25
|
+
const userCookie = cookieStore.get('saas-factory-auth-user')?.value
|
|
26
|
+
|
|
27
|
+
if (!authToken || !userCookie) {
|
|
28
|
+
return null
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Parse user data from cookie
|
|
32
|
+
try {
|
|
33
|
+
const userData = JSON.parse(userCookie)
|
|
34
|
+
return userData
|
|
35
|
+
} catch {
|
|
36
|
+
return null
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error('Error getting current user:', error)
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Require authentication - redirects to login if not authenticated
|
|
46
|
+
* Use this in Server Components that require authentication
|
|
47
|
+
*/
|
|
48
|
+
export async function requireAuth(): Promise<User> {
|
|
49
|
+
const user = await getCurrentUser()
|
|
50
|
+
|
|
51
|
+
if (!user) {
|
|
52
|
+
redirect('/login')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return user
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Check if user is authenticated (without redirecting)
|
|
60
|
+
* Returns boolean for conditional rendering
|
|
61
|
+
*/
|
|
62
|
+
export async function isAuthenticated(): Promise<boolean> {
|
|
63
|
+
const user = await getCurrentUser()
|
|
64
|
+
return !!user
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Redirect if already authenticated
|
|
69
|
+
* Use this on login/signup pages
|
|
70
|
+
*/
|
|
71
|
+
export async function redirectIfAuthenticated(redirectTo: string = '/') {
|
|
72
|
+
const user = await getCurrentUser()
|
|
73
|
+
|
|
74
|
+
if (user) {
|
|
75
|
+
redirect(redirectTo)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get user session data for server components
|
|
81
|
+
* Returns both user and loading state info
|
|
82
|
+
*/
|
|
83
|
+
export async function getServerSession() {
|
|
84
|
+
const user = await getCurrentUser()
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
user,
|
|
88
|
+
isAuthenticated: !!user,
|
|
89
|
+
isLoading: false, // Server-side is never loading
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Server-side auth check for API routes
|
|
95
|
+
*/
|
|
96
|
+
export async function getAuthFromRequest(request?: Request): Promise<User | null> {
|
|
97
|
+
try {
|
|
98
|
+
// If request is provided, extract cookies from it
|
|
99
|
+
if (request) {
|
|
100
|
+
const cookie = request.headers.get('cookie')
|
|
101
|
+
if (!cookie) return null
|
|
102
|
+
|
|
103
|
+
// Parse cookies manually from request
|
|
104
|
+
const cookies = cookie.split(';').reduce((acc, cookie) => {
|
|
105
|
+
const [key, value] = cookie.trim().split('=')
|
|
106
|
+
acc[key] = value
|
|
107
|
+
return acc
|
|
108
|
+
}, {} as Record<string, string>)
|
|
109
|
+
|
|
110
|
+
const authToken = cookies['saas-factory-auth-token']
|
|
111
|
+
const userCookie = cookies['saas-factory-auth-user']
|
|
112
|
+
|
|
113
|
+
if (!authToken || !userCookie) {
|
|
114
|
+
return null
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
const userData = JSON.parse(decodeURIComponent(userCookie))
|
|
119
|
+
return userData
|
|
120
|
+
} catch {
|
|
121
|
+
return null
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Fallback to cookies() API
|
|
126
|
+
return await getCurrentUser()
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error('Error getting auth from request:', error)
|
|
129
|
+
return null
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Create server action wrapper that requires authentication
|
|
135
|
+
*/
|
|
136
|
+
export function withAuth<T extends any[], R>(
|
|
137
|
+
action: (user: User, ...args: T) => Promise<R>
|
|
138
|
+
) {
|
|
139
|
+
return async (...args: T): Promise<R> => {
|
|
140
|
+
const user = await requireAuth()
|
|
141
|
+
return action(user, ...args)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Server-side utility to check specific roles/permissions
|
|
147
|
+
* Extend this based on your user data structure
|
|
148
|
+
*/
|
|
149
|
+
export async function hasRole(role: string): Promise<boolean> {
|
|
150
|
+
const user = await getCurrentUser()
|
|
151
|
+
|
|
152
|
+
if (!user) return false
|
|
153
|
+
|
|
154
|
+
// Assuming role is stored in user.role or user.roles
|
|
155
|
+
if (Array.isArray(user.roles)) {
|
|
156
|
+
return user.roles.includes(role)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return user.role === role
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Server-side utility to require specific roles
|
|
164
|
+
*/
|
|
165
|
+
export async function requireRole(role: string): Promise<User> {
|
|
166
|
+
const user = await requireAuth()
|
|
167
|
+
|
|
168
|
+
const hasRequiredRole = Array.isArray(user.roles)
|
|
169
|
+
? user.roles.includes(role)
|
|
170
|
+
: user.role === role
|
|
171
|
+
|
|
172
|
+
if (!hasRequiredRole) {
|
|
173
|
+
redirect('/unauthorized')
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return user
|
|
177
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional Environment Configuration with Zod validation
|
|
3
|
+
*
|
|
4
|
+
* This provides type-safe environment variable validation.
|
|
5
|
+
* Usage is optional - existing templates will continue to work without this.
|
|
6
|
+
*
|
|
7
|
+
* To use: import { env } from '@/lib/env' instead of process.env
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { z } from 'zod'
|
|
11
|
+
|
|
12
|
+
const envSchema = z.object({
|
|
13
|
+
// Next.js built-in
|
|
14
|
+
NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
|
|
15
|
+
|
|
16
|
+
// App configuration
|
|
17
|
+
NEXT_PUBLIC_APP_URL: z.string().url().optional(),
|
|
18
|
+
NEXT_PUBLIC_APP_NAME: z.string().default('{{titleCaseName}}'),
|
|
19
|
+
|
|
20
|
+
// Auth configuration (if using server-side auth)
|
|
21
|
+
SUPABASE_URL: z.string().url().optional(),
|
|
22
|
+
SUPABASE_ANON_KEY: z.string().optional(),
|
|
23
|
+
SUPABASE_SERVICE_ROLE_KEY: z.string().optional(),
|
|
24
|
+
|
|
25
|
+
// Payment configuration
|
|
26
|
+
STRIPE_SECRET_KEY: z.string().optional(),
|
|
27
|
+
STRIPE_WEBHOOK_SECRET: z.string().optional(),
|
|
28
|
+
|
|
29
|
+
// Optional analytics
|
|
30
|
+
ANALYTICS_ID: z.string().optional(),
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
// Parse with fallback to process.env for backward compatibility
|
|
34
|
+
function parseEnv() {
|
|
35
|
+
try {
|
|
36
|
+
return envSchema.parse(process.env)
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (process.env.NODE_ENV === 'development') {
|
|
39
|
+
console.warn('Environment validation failed. Using process.env fallback:', error)
|
|
40
|
+
}
|
|
41
|
+
// Fallback to process.env for backward compatibility
|
|
42
|
+
return process.env as any
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const env = parseEnv()
|
|
47
|
+
|
|
48
|
+
// Type helper for environment variables
|
|
49
|
+
export type Env = z.infer<typeof envSchema>
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced utility functions for {{titleCaseName}}
|
|
3
|
+
*
|
|
4
|
+
* This extends the basic utils with additional functionality while
|
|
5
|
+
* maintaining compatibility with existing templates.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { type ClassValue, clsx } from "clsx"
|
|
9
|
+
import { twMerge } from "tailwind-merge"
|
|
10
|
+
|
|
11
|
+
// Core utility function (keeps existing functionality)
|
|
12
|
+
export function cn(...inputs: ClassValue[]) {
|
|
13
|
+
return twMerge(clsx(inputs))
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Additional utilities for enhanced templates
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Format currency with proper locale support
|
|
20
|
+
*/
|
|
21
|
+
export function formatCurrency(
|
|
22
|
+
amount: number,
|
|
23
|
+
currency: string = 'USD',
|
|
24
|
+
locale: string = 'en-US'
|
|
25
|
+
): string {
|
|
26
|
+
return new Intl.NumberFormat(locale, {
|
|
27
|
+
style: 'currency',
|
|
28
|
+
currency,
|
|
29
|
+
}).format(amount)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Format date with relative time support
|
|
34
|
+
*/
|
|
35
|
+
export function formatDate(
|
|
36
|
+
date: Date | string,
|
|
37
|
+
options?: Intl.DateTimeFormatOptions
|
|
38
|
+
): string {
|
|
39
|
+
const dateObj = typeof date === 'string' ? new Date(date) : date
|
|
40
|
+
|
|
41
|
+
const defaultOptions: Intl.DateTimeFormatOptions = {
|
|
42
|
+
year: 'numeric',
|
|
43
|
+
month: 'short',
|
|
44
|
+
day: 'numeric',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return new Intl.DateTimeFormat('en-US', options || defaultOptions).format(dateObj)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get relative time string (e.g., "2 hours ago")
|
|
52
|
+
*/
|
|
53
|
+
export function getRelativeTime(date: Date | string): string {
|
|
54
|
+
const dateObj = typeof date === 'string' ? new Date(date) : date
|
|
55
|
+
const now = new Date()
|
|
56
|
+
const diffInMs = now.getTime() - dateObj.getTime()
|
|
57
|
+
const diffInSeconds = Math.floor(diffInMs / 1000)
|
|
58
|
+
const diffInMinutes = Math.floor(diffInSeconds / 60)
|
|
59
|
+
const diffInHours = Math.floor(diffInMinutes / 60)
|
|
60
|
+
const diffInDays = Math.floor(diffInHours / 24)
|
|
61
|
+
|
|
62
|
+
if (diffInSeconds < 60) return 'just now'
|
|
63
|
+
if (diffInMinutes < 60) return `${diffInMinutes} minute${diffInMinutes > 1 ? 's' : ''} ago`
|
|
64
|
+
if (diffInHours < 24) return `${diffInHours} hour${diffInHours > 1 ? 's' : ''} ago`
|
|
65
|
+
if (diffInDays < 7) return `${diffInDays} day${diffInDays > 1 ? 's' : ''} ago`
|
|
66
|
+
|
|
67
|
+
return formatDate(dateObj)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Truncate text to specified length with ellipsis
|
|
72
|
+
*/
|
|
73
|
+
export function truncate(text: string, length: number = 50): string {
|
|
74
|
+
if (text.length <= length) return text
|
|
75
|
+
return text.slice(0, length).trim() + '...'
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Generate initials from a name
|
|
80
|
+
*/
|
|
81
|
+
export function getInitials(name: string): string {
|
|
82
|
+
return name
|
|
83
|
+
.split(' ')
|
|
84
|
+
.map(word => word.charAt(0).toUpperCase())
|
|
85
|
+
.slice(0, 2)
|
|
86
|
+
.join('')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Validate email format
|
|
91
|
+
*/
|
|
92
|
+
export function isValidEmail(email: string): boolean {
|
|
93
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
|
94
|
+
return emailRegex.test(email)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Generate a random ID
|
|
99
|
+
*/
|
|
100
|
+
export function generateId(prefix: string = ''): string {
|
|
101
|
+
const timestamp = Date.now().toString(36)
|
|
102
|
+
const randomString = Math.random().toString(36).substring(2)
|
|
103
|
+
return prefix ? `${prefix}-${timestamp}-${randomString}` : `${timestamp}-${randomString}`
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Debounce function
|
|
108
|
+
*/
|
|
109
|
+
export function debounce<T extends (...args: any[]) => any>(
|
|
110
|
+
func: T,
|
|
111
|
+
delay: number
|
|
112
|
+
): (...args: Parameters<T>) => void {
|
|
113
|
+
let timeoutId: NodeJS.Timeout | null = null
|
|
114
|
+
|
|
115
|
+
return (...args: Parameters<T>) => {
|
|
116
|
+
if (timeoutId !== null) {
|
|
117
|
+
clearTimeout(timeoutId)
|
|
118
|
+
}
|
|
119
|
+
timeoutId = setTimeout(() => func(...args), delay)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Sleep/delay function for async operations
|
|
125
|
+
*/
|
|
126
|
+
export function sleep(ms: number): Promise<void> {
|
|
127
|
+
return new Promise(resolve => setTimeout(resolve, ms))
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Safe JSON parse with fallback
|
|
132
|
+
*/
|
|
133
|
+
export function safeJsonParse<T>(json: string, fallback: T): T {
|
|
134
|
+
try {
|
|
135
|
+
return JSON.parse(json)
|
|
136
|
+
} catch {
|
|
137
|
+
return fallback
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import '@testing-library/jest-dom'
|
|
2
|
+
import { vi, beforeEach, afterAll } from 'vitest'
|
|
3
|
+
|
|
4
|
+
// Mock Next.js router
|
|
5
|
+
vi.mock('next/navigation', () => ({
|
|
6
|
+
useRouter: () => ({
|
|
7
|
+
push: vi.fn(),
|
|
8
|
+
back: vi.fn(),
|
|
9
|
+
forward: vi.fn(),
|
|
10
|
+
refresh: vi.fn(),
|
|
11
|
+
replace: vi.fn(),
|
|
12
|
+
prefetch: vi.fn(),
|
|
13
|
+
}),
|
|
14
|
+
useSearchParams: () => new URLSearchParams(),
|
|
15
|
+
usePathname: () => '/',
|
|
16
|
+
}))
|
|
17
|
+
|
|
18
|
+
// Mock SaaS Factory Auth (optional - only if testing auth components)
|
|
19
|
+
vi.mock('@digilogiclabs/saas-factory-auth', () => ({
|
|
20
|
+
useAuth: () => ({
|
|
21
|
+
user: null,
|
|
22
|
+
loading: false,
|
|
23
|
+
error: null,
|
|
24
|
+
signIn: vi.fn(),
|
|
25
|
+
signUp: vi.fn(),
|
|
26
|
+
signOut: vi.fn(),
|
|
27
|
+
signInWithOAuth: vi.fn(),
|
|
28
|
+
}),
|
|
29
|
+
AuthProvider: ({ children }: { children: React.ReactNode }) => children,
|
|
30
|
+
}))
|
|
31
|
+
|
|
32
|
+
// Mock SaaS Factory Payments (optional - only if testing payment components)
|
|
33
|
+
vi.mock('@digilogiclabs/saas-factory-payments', () => ({
|
|
34
|
+
usePayments: () => ({
|
|
35
|
+
createCheckoutSession: vi.fn(),
|
|
36
|
+
createPortalSession: vi.fn(),
|
|
37
|
+
subscription: null,
|
|
38
|
+
loading: false,
|
|
39
|
+
}),
|
|
40
|
+
PaymentsProvider: ({ children }: { children: React.ReactNode }) => children,
|
|
41
|
+
}))
|
|
42
|
+
|
|
43
|
+
// Global test utilities
|
|
44
|
+
global.ResizeObserver = vi.fn().mockImplementation(() => ({
|
|
45
|
+
observe: vi.fn(),
|
|
46
|
+
unobserve: vi.fn(),
|
|
47
|
+
disconnect: vi.fn(),
|
|
48
|
+
}))
|
|
49
|
+
|
|
50
|
+
// Suppress console warnings in tests unless needed
|
|
51
|
+
const originalConsoleError = console.error
|
|
52
|
+
const originalConsoleWarn = console.warn
|
|
53
|
+
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
console.error = (...args: any[]) => {
|
|
56
|
+
if (
|
|
57
|
+
typeof args[0] === 'string' &&
|
|
58
|
+
args[0].includes('Warning: ReactDOM.render is no longer supported')
|
|
59
|
+
) {
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
originalConsoleError.call(console, ...args)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
console.warn = (...args: any[]) => {
|
|
66
|
+
if (
|
|
67
|
+
typeof args[0] === 'string' &&
|
|
68
|
+
args[0].includes('useLayoutEffect does nothing on the server')
|
|
69
|
+
) {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
originalConsoleWarn.call(console, ...args)
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
afterAll(() => {
|
|
77
|
+
console.error = originalConsoleError
|
|
78
|
+
console.warn = originalConsoleWarn
|
|
79
|
+
})
|