@digilogiclabs/create-saas-app 1.5.1 → 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.
Files changed (115) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/cli/commands/add.d.ts +6 -0
  3. package/dist/cli/commands/add.d.ts.map +1 -0
  4. package/dist/cli/commands/add.js +39 -0
  5. package/dist/cli/commands/add.js.map +1 -0
  6. package/dist/cli/commands/create.d.ts +28 -0
  7. package/dist/cli/commands/create.d.ts.map +1 -0
  8. package/dist/cli/commands/create.js +130 -0
  9. package/dist/cli/commands/create.js.map +1 -0
  10. package/dist/cli/commands/index.d.ts +4 -0
  11. package/dist/cli/commands/index.d.ts.map +1 -0
  12. package/dist/cli/commands/index.js +20 -0
  13. package/dist/cli/commands/index.js.map +1 -0
  14. package/dist/cli/commands/update.d.ts +6 -0
  15. package/dist/cli/commands/update.d.ts.map +1 -0
  16. package/dist/cli/commands/update.js +68 -0
  17. package/dist/cli/commands/update.js.map +1 -0
  18. package/dist/{index.d.ts → cli/index.d.ts} +2 -3
  19. package/dist/cli/index.d.ts.map +1 -0
  20. package/dist/cli/index.js +59 -0
  21. package/dist/cli/index.js.map +1 -0
  22. package/dist/cli/prompts/index.d.ts +2 -0
  23. package/dist/cli/prompts/index.d.ts.map +1 -0
  24. package/dist/cli/prompts/index.js +18 -0
  25. package/dist/cli/prompts/index.js.map +1 -0
  26. package/dist/cli/prompts/project-setup.d.ts +5 -0
  27. package/dist/cli/prompts/project-setup.d.ts.map +1 -0
  28. package/dist/cli/prompts/project-setup.js +251 -0
  29. package/dist/cli/prompts/project-setup.js.map +1 -0
  30. package/dist/cli/utils/git.d.ts +9 -0
  31. package/dist/cli/utils/git.d.ts.map +1 -0
  32. package/dist/cli/utils/git.js +77 -0
  33. package/dist/cli/utils/git.js.map +1 -0
  34. package/dist/cli/utils/index.d.ts +5 -0
  35. package/dist/cli/utils/index.d.ts.map +1 -0
  36. package/dist/cli/utils/index.js +21 -0
  37. package/dist/cli/utils/index.js.map +1 -0
  38. package/dist/cli/utils/logger.d.ts +16 -0
  39. package/dist/cli/utils/logger.d.ts.map +1 -0
  40. package/dist/cli/utils/logger.js +55 -0
  41. package/dist/cli/utils/logger.js.map +1 -0
  42. package/dist/cli/utils/package-manager.d.ts +8 -0
  43. package/dist/cli/utils/package-manager.d.ts.map +1 -0
  44. package/dist/cli/utils/package-manager.js +92 -0
  45. package/dist/cli/utils/package-manager.js.map +1 -0
  46. package/dist/cli/utils/spinner.d.ts +7 -0
  47. package/dist/cli/utils/spinner.d.ts.map +1 -0
  48. package/dist/cli/utils/spinner.js +48 -0
  49. package/dist/cli/utils/spinner.js.map +1 -0
  50. package/dist/cli/validators/dependencies.d.ts +15 -0
  51. package/dist/cli/validators/dependencies.d.ts.map +1 -0
  52. package/dist/cli/validators/dependencies.js +108 -0
  53. package/dist/cli/validators/dependencies.js.map +1 -0
  54. package/dist/cli/validators/index.d.ts +3 -0
  55. package/dist/cli/validators/index.d.ts.map +1 -0
  56. package/dist/cli/validators/index.js +19 -0
  57. package/dist/cli/validators/index.js.map +1 -0
  58. package/dist/cli/validators/project-name.d.ts +5 -0
  59. package/dist/cli/validators/project-name.d.ts.map +1 -0
  60. package/dist/cli/validators/project-name.js +151 -0
  61. package/dist/cli/validators/project-name.js.map +1 -0
  62. package/dist/generators/file-processor.d.ts +28 -0
  63. package/dist/generators/file-processor.d.ts.map +1 -0
  64. package/dist/generators/file-processor.js +203 -0
  65. package/dist/generators/file-processor.js.map +1 -0
  66. package/dist/generators/index.d.ts +4 -0
  67. package/dist/generators/index.d.ts.map +1 -0
  68. package/dist/generators/index.js +20 -0
  69. package/dist/generators/index.js.map +1 -0
  70. package/dist/generators/package-installer.d.ts +29 -0
  71. package/dist/generators/package-installer.d.ts.map +1 -0
  72. package/dist/generators/package-installer.js +167 -0
  73. package/dist/generators/package-installer.js.map +1 -0
  74. package/dist/generators/template-generator.d.ts +48 -0
  75. package/dist/generators/template-generator.d.ts.map +1 -0
  76. package/dist/generators/template-generator.js +276 -0
  77. package/dist/generators/template-generator.js.map +1 -0
  78. package/dist/index.js +3 -3
  79. package/dist/index.js.map +1 -1
  80. package/dist/templates/web/ui-auth-payments/template/package-lock.json +12240 -0
  81. package/dist/templates/web/ui-auth-payments/template/src/components/client/login-form.tsx +1 -1
  82. package/dist/templates/web/ui-auth-payments/template/src/components/client/signup-form.tsx +3 -3
  83. package/dist/templates/web/ui-auth-payments/template/tsconfig.tsbuildinfo +1 -0
  84. package/dist/templates/web/ui-auth-payments-audio/template/middleware.ts +68 -0
  85. package/dist/templates/web/ui-auth-payments-audio/template/package-lock.json +12241 -0
  86. package/dist/templates/web/ui-auth-payments-audio/template/src/app/dashboard/layout.tsx +22 -0
  87. package/dist/templates/web/ui-auth-payments-audio/template/src/app/dashboard/page.tsx +183 -0
  88. package/dist/templates/web/ui-auth-payments-audio/template/src/app/login/page.tsx +2 -105
  89. package/dist/templates/web/ui-auth-payments-audio/template/src/app/signup/page.tsx +2 -124
  90. package/dist/templates/web/ui-auth-payments-audio/template/src/components/client/auth-status.tsx +52 -0
  91. package/dist/templates/web/ui-auth-payments-audio/template/src/components/client/login-form.tsx +144 -0
  92. package/dist/templates/web/ui-auth-payments-audio/template/src/components/client/signup-form.tsx +185 -0
  93. package/dist/templates/web/ui-auth-payments-audio/template/src/lib/actions/auth.ts +246 -0
  94. package/dist/templates/web/ui-auth-payments-audio/template/src/lib/actions/index.ts +14 -0
  95. package/dist/templates/web/ui-auth-payments-audio/template/src/lib/auth-server.ts +177 -0
  96. package/dist/templates/web/ui-auth-payments-audio/template/tsconfig.tsbuildinfo +1 -0
  97. package/dist/templates/web/ui-package-test/template/next-env.d.ts +5 -0
  98. package/package.json +4 -3
  99. package/src/templates/web/ui-auth-payments/template/package-lock.json +12240 -0
  100. package/src/templates/web/ui-auth-payments/template/src/components/client/login-form.tsx +1 -1
  101. package/src/templates/web/ui-auth-payments/template/src/components/client/signup-form.tsx +3 -3
  102. package/src/templates/web/ui-auth-payments/template/tsconfig.tsbuildinfo +1 -0
  103. package/src/templates/web/ui-auth-payments-audio/template/middleware.ts +68 -0
  104. package/src/templates/web/ui-auth-payments-audio/template/package-lock.json +12241 -0
  105. package/src/templates/web/ui-auth-payments-audio/template/src/app/dashboard/layout.tsx +22 -0
  106. package/src/templates/web/ui-auth-payments-audio/template/src/app/dashboard/page.tsx +183 -0
  107. package/src/templates/web/ui-auth-payments-audio/template/src/app/login/page.tsx +2 -105
  108. package/src/templates/web/ui-auth-payments-audio/template/src/app/signup/page.tsx +2 -124
  109. package/src/templates/web/ui-auth-payments-audio/template/src/components/client/auth-status.tsx +52 -0
  110. package/src/templates/web/ui-auth-payments-audio/template/src/components/client/login-form.tsx +144 -0
  111. package/src/templates/web/ui-auth-payments-audio/template/src/components/client/signup-form.tsx +185 -0
  112. package/src/templates/web/ui-auth-payments-audio/template/src/lib/actions/auth.ts +246 -0
  113. package/src/templates/web/ui-auth-payments-audio/template/src/lib/actions/index.ts +14 -0
  114. package/src/templates/web/ui-auth-payments-audio/template/src/lib/auth-server.ts +177 -0
  115. package/src/templates/web/ui-auth-payments-audio/template/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,22 @@
1
+ import { requireAuth } from '@/lib/auth-server'
2
+ import { redirect } from 'next/navigation'
3
+
4
+ export default async function DashboardLayout({
5
+ children,
6
+ }: {
7
+ children: React.ReactNode
8
+ }) {
9
+ // Ensure user is authenticated at the layout level
10
+ try {
11
+ await requireAuth()
12
+ } catch (error) {
13
+ // This will happen if requireAuth redirects, but just in case
14
+ redirect('/login')
15
+ }
16
+
17
+ return (
18
+ <div className="dashboard-layout">
19
+ {children}
20
+ </div>
21
+ )
22
+ }
@@ -0,0 +1,183 @@
1
+ import { Suspense } from 'react'
2
+ import { Button, Card } from '@digilogiclabs/saas-factory-ui'
3
+ import { User, Settings, CreditCard, Activity } from 'lucide-react'
4
+ import { requireAuth } from '@/lib/auth-server'
5
+ import Link from 'next/link'
6
+
7
+ // Example of server component data fetching
8
+ async function getUserStats(userId: string) {
9
+ // Simulate API call
10
+ await new Promise(resolve => setTimeout(resolve, 100))
11
+
12
+ return {
13
+ totalPosts: 42,
14
+ totalViews: 1337,
15
+ totalLikes: 256,
16
+ joinedDate: '2024-01-15'
17
+ }
18
+ }
19
+
20
+ function StatsCard({ title, value, icon: Icon, href }: {
21
+ title: string
22
+ value: string | number
23
+ icon: React.ComponentType<any>
24
+ href?: string
25
+ }) {
26
+ const content = (
27
+ <Card className="p-6 hover:shadow-lg transition-shadow">
28
+ <div className="flex items-center justify-between">
29
+ <div>
30
+ <p className="text-sm font-medium text-gray-600 dark:text-gray-400">{title}</p>
31
+ <p className="text-2xl font-bold text-gray-900 dark:text-white">{value}</p>
32
+ </div>
33
+ <Icon className="h-8 w-8 text-blue-600 dark:text-blue-400" />
34
+ </div>
35
+ </Card>
36
+ )
37
+
38
+ if (href) {
39
+ return <Link href={href}>{content}</Link>
40
+ }
41
+
42
+ return content
43
+ }
44
+
45
+ async function UserStats({ userId }: { userId: string }) {
46
+ const stats = await getUserStats(userId)
47
+
48
+ return (
49
+ <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
50
+ <StatsCard
51
+ title="Total Posts"
52
+ value={stats.totalPosts}
53
+ icon={Activity}
54
+ />
55
+ <StatsCard
56
+ title="Total Views"
57
+ value={stats.totalViews.toLocaleString()}
58
+ icon={Activity}
59
+ />
60
+ <StatsCard
61
+ title="Total Likes"
62
+ value={stats.totalLikes}
63
+ icon={Activity}
64
+ />
65
+ <StatsCard
66
+ title="Member Since"
67
+ value={new Date(stats.joinedDate).getFullYear()}
68
+ icon={User}
69
+ />
70
+ </div>
71
+ )
72
+ }
73
+
74
+ function UserStatsSkeleton() {
75
+ return (
76
+ <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
77
+ {[...Array(4)].map((_, i) => (
78
+ <Card key={i} className="p-6">
79
+ <div className="animate-pulse">
80
+ <div className="h-4 bg-gray-200 dark:bg-gray-700 rounded w-1/2 mb-2"></div>
81
+ <div className="h-8 bg-gray-200 dark:bg-gray-700 rounded w-1/3"></div>
82
+ </div>
83
+ </Card>
84
+ ))}
85
+ </div>
86
+ )
87
+ }
88
+
89
+ export default async function DashboardPage() {
90
+ // Server-side authentication requirement
91
+ const user = await requireAuth()
92
+
93
+ return (
94
+ <div className="min-h-screen bg-gray-50 dark:bg-gray-900">
95
+ <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
96
+ {/* Header */}
97
+ <div className="mb-8">
98
+ <h1 className="text-3xl font-bold text-gray-900 dark:text-white">
99
+ Welcome back, {user.name || user.email}!
100
+ </h1>
101
+ <p className="text-gray-600 dark:text-gray-300 mt-2">
102
+ Here's what's happening with your account today.
103
+ </p>
104
+ </div>
105
+
106
+ {/* Stats - Streaming with Suspense */}
107
+ <Suspense fallback={<UserStatsSkeleton />}>
108
+ <UserStats userId={user.id} />
109
+ </Suspense>
110
+
111
+ {/* Quick Actions */}
112
+ <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-8">
113
+ <Card className="p-6">
114
+ <div className="flex items-center mb-4">
115
+ <User className="h-6 w-6 text-blue-600 dark:text-blue-400 mr-3" />
116
+ <h3 className="text-lg font-semibold text-gray-900 dark:text-white">Profile</h3>
117
+ </div>
118
+ <p className="text-gray-600 dark:text-gray-300 mb-4">
119
+ Update your personal information and preferences
120
+ </p>
121
+ <Link href="/profile">
122
+ <Button className="w-full">Manage Profile</Button>
123
+ </Link>
124
+ </Card>
125
+
126
+ <Card className="p-6">
127
+ <div className="flex items-center mb-4">
128
+ <Settings className="h-6 w-6 text-blue-600 dark:text-blue-400 mr-3" />
129
+ <h3 className="text-lg font-semibold text-gray-900 dark:text-white">Settings</h3>
130
+ </div>
131
+ <p className="text-gray-600 dark:text-gray-300 mb-4">
132
+ Configure your account settings and security options
133
+ </p>
134
+ <Link href="/settings">
135
+ <Button variant="outline" className="w-full">Open Settings</Button>
136
+ </Link>
137
+ </Card>
138
+
139
+ <Card className="p-6">
140
+ <div className="flex items-center mb-4">
141
+ <CreditCard className="h-6 w-6 text-blue-600 dark:text-blue-400 mr-3" />
142
+ <h3 className="text-lg font-semibold text-gray-900 dark:text-white">Billing</h3>
143
+ </div>
144
+ <p className="text-gray-600 dark:text-gray-300 mb-4">
145
+ View your subscription and payment information
146
+ </p>
147
+ <Link href="/billing">
148
+ <Button variant="outline" className="w-full">View Billing</Button>
149
+ </Link>
150
+ </Card>
151
+ </div>
152
+
153
+ {/* Recent Activity */}
154
+ <Card className="p-6">
155
+ <h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-4">Recent Activity</h3>
156
+ <div className="space-y-4">
157
+ <div className="flex items-center justify-between py-3 border-b border-gray-200 dark:border-gray-700">
158
+ <div className="flex items-center">
159
+ <div className="w-2 h-2 bg-green-500 rounded-full mr-3"></div>
160
+ <span className="text-gray-900 dark:text-white">Account created</span>
161
+ </div>
162
+ <span className="text-sm text-gray-500 dark:text-gray-400">2 days ago</span>
163
+ </div>
164
+ <div className="flex items-center justify-between py-3 border-b border-gray-200 dark:border-gray-700">
165
+ <div className="flex items-center">
166
+ <div className="w-2 h-2 bg-blue-500 rounded-full mr-3"></div>
167
+ <span className="text-gray-900 dark:text-white">Profile updated</span>
168
+ </div>
169
+ <span className="text-sm text-gray-500 dark:text-gray-400">1 week ago</span>
170
+ </div>
171
+ <div className="flex items-center justify-between py-3">
172
+ <div className="flex items-center">
173
+ <div className="w-2 h-2 bg-purple-500 rounded-full mr-3"></div>
174
+ <span className="text-gray-900 dark:text-white">Subscription started</span>
175
+ </div>
176
+ <span className="text-sm text-gray-500 dark:text-gray-400">2 weeks ago</span>
177
+ </div>
178
+ </div>
179
+ </Card>
180
+ </div>
181
+ </div>
182
+ )
183
+ }
@@ -1,109 +1,6 @@
1
- 'use client';
2
-
3
- import React, { useState } from 'react';
4
- import { Button, Card, Input, Label } from '@digilogiclabs/saas-factory-ui';
5
- import { useAuth } from '@digilogiclabs/saas-factory-auth';
6
- import { useRouter } from 'next/navigation';
1
+ import { LoginForm } from '@/components/client/login-form'
7
2
 
8
3
  export default function LoginPage() {
9
- const [email, setEmail] = useState('');
10
- const [password, setPassword] = useState('');
11
- const { signIn, signInWithOAuth, loading, error, user } = useAuth();
12
- const router = useRouter();
13
-
14
- // Redirect if already logged in
15
- React.useEffect(() => {
16
- if (user) {
17
- router.push('/');
18
- }
19
- }, [user, router]);
20
-
21
- const handleLogin = async (e: React.FormEvent) => {
22
- e.preventDefault();
23
- try {
24
- await signIn(email, password);
25
- router.push('/');
26
- } catch (err) {
27
- console.error('Login error:', err);
28
- }
29
- };
30
-
31
- const handleGoogleLogin = async () => {
32
- try {
33
- await signInWithOAuth('google', window.location.origin);
34
- } catch (err) {
35
- console.error('Google login error:', err);
36
- }
37
- };
38
-
39
- if (loading) {
40
- return (
41
- <div className="flex items-center justify-center min-h-screen bg-gray-100">
42
- <div>Loading...</div>
43
- </div>
44
- );
45
- }
46
-
47
- return (
48
- <div className="flex items-center justify-center min-h-screen bg-gray-100">
49
- <Card className="w-full max-w-md p-8">
50
- <h1 className="text-2xl font-bold text-center mb-6">Sign In</h1>
51
-
52
- {error && (
53
- <div className="mb-4 p-3 bg-red-100 border border-red-400 text-red-700 rounded">
54
- {error.message}
55
- </div>
56
- )}
57
-
58
- <form onSubmit={handleLogin} className="space-y-4">
59
- <div>
60
- <Label htmlFor="email">Email</Label>
61
- <Input
62
- id="email"
63
- type="email"
64
- value={email}
65
- onChange={(e) => setEmail(e.target.value)}
66
- placeholder="Enter your email"
67
- required
68
- disabled={loading}
69
- />
70
- </div>
71
- <div>
72
- <Label htmlFor="password">Password</Label>
73
- <Input
74
- id="password"
75
- type="password"
76
- value={password}
77
- onChange={(e) => setPassword(e.target.value)}
78
- placeholder="Enter your password"
79
- required
80
- disabled={loading}
81
- />
82
- </div>
83
- <Button type="submit" className="w-full" disabled={loading}>
84
- {loading ? 'Signing In...' : 'Sign In'}
85
- </Button>
86
- <Button
87
- type="button"
88
- variant="outline"
89
- className="w-full"
90
- onClick={handleGoogleLogin}
91
- disabled={loading}
92
- >
93
- Sign in with Google
94
- </Button>
95
- </form>
96
-
97
- <div className="mt-4 text-center">
98
- <p className="text-sm text-gray-600">
99
- Don&apos;t have an account?{' '}
100
- <a href="/signup" className="text-blue-600 hover:underline">
101
- Sign up
102
- </a>
103
- </p>
104
- </div>
105
- </Card>
106
- </div>
107
- );
4
+ return <LoginForm />
108
5
  }
109
6
 
@@ -1,128 +1,6 @@
1
- 'use client';
2
-
3
- import React, { useState } from 'react';
4
- import { Button, Card, Input, Label } from '@digilogiclabs/saas-factory-ui';
5
- import { useAuth } from '@digilogiclabs/saas-factory-auth';
6
- import { useRouter } from 'next/navigation';
1
+ import { SignupForm } from '@/components/client/signup-form'
7
2
 
8
3
  export default function SignupPage() {
9
- const [email, setEmail] = useState('');
10
- const [password, setPassword] = useState('');
11
- const [confirmPassword, setConfirmPassword] = useState('');
12
- const { signUp, signInWithOAuth, loading, error, user } = useAuth();
13
- const router = useRouter();
14
-
15
- // Redirect if already logged in
16
- React.useEffect(() => {
17
- if (user) {
18
- router.push('/');
19
- }
20
- }, [user, router]);
21
-
22
- const handleSignup = async (e: React.FormEvent) => {
23
- e.preventDefault();
24
-
25
- if (password !== confirmPassword) {
26
- alert('Passwords do not match');
27
- return;
28
- }
29
-
30
- try {
31
- await signUp(email, password);
32
- router.push('/');
33
- } catch (err) {
34
- console.error('Signup error:', err);
35
- }
36
- };
37
-
38
- const handleGoogleSignup = async () => {
39
- try {
40
- await signInWithOAuth('google', window.location.origin);
41
- } catch (err) {
42
- console.error('Google signup error:', err);
43
- }
44
- };
45
-
46
- if (loading) {
47
- return (
48
- <div className="flex items-center justify-center min-h-screen bg-gray-100">
49
- <div>Loading...</div>
50
- </div>
51
- );
52
- }
53
-
54
- return (
55
- <div className="flex items-center justify-center min-h-screen bg-gray-100">
56
- <Card className="w-full max-w-md p-8">
57
- <h1 className="text-2xl font-bold text-center mb-6">Sign Up</h1>
58
-
59
- {error && (
60
- <div className="mb-4 p-3 bg-red-100 border border-red-400 text-red-700 rounded">
61
- {error.message}
62
- </div>
63
- )}
64
-
65
- <form onSubmit={handleSignup} className="space-y-4">
66
- <div>
67
- <Label htmlFor="email">Email</Label>
68
- <Input
69
- id="email"
70
- type="email"
71
- value={email}
72
- onChange={(e) => setEmail(e.target.value)}
73
- placeholder="Enter your email"
74
- required
75
- disabled={loading}
76
- />
77
- </div>
78
- <div>
79
- <Label htmlFor="password">Password</Label>
80
- <Input
81
- id="password"
82
- type="password"
83
- value={password}
84
- onChange={(e) => setPassword(e.target.value)}
85
- placeholder="Enter your password"
86
- required
87
- disabled={loading}
88
- />
89
- </div>
90
- <div>
91
- <Label htmlFor="confirmPassword">Confirm Password</Label>
92
- <Input
93
- id="confirmPassword"
94
- type="password"
95
- value={confirmPassword}
96
- onChange={(e) => setConfirmPassword(e.target.value)}
97
- placeholder="Confirm your password"
98
- required
99
- disabled={loading}
100
- />
101
- </div>
102
- <Button type="submit" className="w-full" disabled={loading}>
103
- {loading ? 'Signing Up...' : 'Sign Up'}
104
- </Button>
105
- <Button
106
- type="button"
107
- variant="outline"
108
- className="w-full"
109
- onClick={handleGoogleSignup}
110
- disabled={loading}
111
- >
112
- Sign up with Google
113
- </Button>
114
- </form>
115
-
116
- <div className="mt-4 text-center">
117
- <p className="text-sm text-gray-600">
118
- Already have an account?{' '}
119
- <a href="/login" className="text-blue-600 hover:underline">
120
- Sign in
121
- </a>
122
- </p>
123
- </div>
124
- </Card>
125
- </div>
126
- );
4
+ return <SignupForm />
127
5
  }
128
6
 
@@ -0,0 +1,52 @@
1
+ 'use client'
2
+
3
+ import { Button } from '@digilogiclabs/saas-factory-ui'
4
+ import { LogOut, User } from 'lucide-react'
5
+ import { useAuth } from '@digilogiclabs/saas-factory-auth'
6
+ import Link from 'next/link'
7
+
8
+ export function AuthStatus() {
9
+ const { user, signOut, loading } = useAuth()
10
+
11
+ const handleSignOut = async () => {
12
+ try {
13
+ await signOut()
14
+ } catch (err) {
15
+ console.error('Sign out error:', err)
16
+ }
17
+ }
18
+
19
+ if (loading) {
20
+ return (
21
+ <div className="text-sm text-gray-600 dark:text-gray-300">
22
+ Loading...
23
+ </div>
24
+ )
25
+ }
26
+
27
+ if (user) {
28
+ return (
29
+ <div className="flex items-center gap-4">
30
+ <div className="flex items-center gap-2 text-sm text-gray-600 dark:text-gray-300">
31
+ <User className="w-4 h-4" />
32
+ Welcome, {user.email}
33
+ </div>
34
+ <Button variant="outline" size="sm" onClick={handleSignOut}>
35
+ <LogOut className="w-4 h-4 mr-2" />
36
+ Sign Out
37
+ </Button>
38
+ </div>
39
+ )
40
+ }
41
+
42
+ return (
43
+ <div className="flex gap-2">
44
+ <Link href="/login">
45
+ <Button variant="outline" size="sm">Sign In</Button>
46
+ </Link>
47
+ <Link href="/signup">
48
+ <Button size="sm">Sign Up</Button>
49
+ </Link>
50
+ </div>
51
+ )
52
+ }
@@ -0,0 +1,144 @@
1
+ 'use client'
2
+
3
+ import React, { useState, useActionState } from 'react'
4
+ import { Button, Card, Input, Label } from '@digilogiclabs/saas-factory-ui'
5
+ import { useAuth } from '@digilogiclabs/saas-factory-auth'
6
+ import { useRouter } from 'next/navigation'
7
+ import { signInAction } from '@/lib/actions/auth'
8
+
9
+ export function LoginForm() {
10
+ const [email, setEmail] = useState('')
11
+ const [password, setPassword] = useState('')
12
+ const { signIn, signInWithOAuth, loading, error, user } = useAuth()
13
+ const [actionState, formAction] = useActionState(signInAction, { success: false })
14
+ const router = useRouter()
15
+
16
+ // Redirect if already logged in
17
+ React.useEffect(() => {
18
+ if (user) {
19
+ router.push('/')
20
+ }
21
+ }, [user, router])
22
+
23
+ const handleLogin = async (e: React.FormEvent) => {
24
+ e.preventDefault()
25
+ try {
26
+ await signIn(email, password)
27
+ router.push('/')
28
+ } catch (err) {
29
+ console.error('Login error:', err)
30
+ }
31
+ }
32
+
33
+ const handleGoogleLogin = async () => {
34
+ try {
35
+ await signInWithOAuth('google', window.location.origin)
36
+ } catch (err) {
37
+ console.error('Google login error:', err)
38
+ }
39
+ }
40
+
41
+ // Enhanced form action that uses both server action validation and client auth
42
+ const handleServerAction = async (formData: FormData) => {
43
+ const result = await formAction(formData)
44
+
45
+ if (result?.success) {
46
+ // If server validation passes, proceed with client auth
47
+ const emailValue = formData.get('email') as string
48
+ const passwordValue = formData.get('password') as string
49
+
50
+ try {
51
+ await signIn(emailValue, passwordValue)
52
+ router.push('/')
53
+ } catch (err) {
54
+ console.error('Login error:', err)
55
+ }
56
+ }
57
+ }
58
+
59
+ if (loading) {
60
+ return (
61
+ <div className="flex items-center justify-center min-h-screen bg-gray-100 dark:bg-gray-900">
62
+ <div>Loading...</div>
63
+ </div>
64
+ )
65
+ }
66
+
67
+ return (
68
+ <div className="flex items-center justify-center min-h-screen bg-gray-100 dark:bg-gray-900">
69
+ <Card className="w-full max-w-md p-8">
70
+ <h1 className="text-2xl font-bold text-center mb-6">Sign In</h1>
71
+
72
+ {/* Server action errors */}
73
+ {actionState?.error && (
74
+ <div className="mb-4 p-3 bg-red-100 border border-red-400 text-red-700 rounded">
75
+ {actionState.error}
76
+ </div>
77
+ )}
78
+
79
+ {/* Client auth errors */}
80
+ {error && (
81
+ <div className="mb-4 p-3 bg-red-100 border border-red-400 text-red-700 rounded">
82
+ {error.message}
83
+ </div>
84
+ )}
85
+
86
+ <form action={handleServerAction} className="space-y-4">
87
+ <div>
88
+ <Label htmlFor="email">Email</Label>
89
+ <Input
90
+ id="email"
91
+ name="email"
92
+ type="email"
93
+ value={email}
94
+ onChange={(e) => setEmail(e.target.value)}
95
+ placeholder="Enter your email"
96
+ required
97
+ disabled={loading}
98
+ />
99
+ {actionState?.fieldErrors?.email && (
100
+ <p className="text-sm text-red-600 mt-1">{actionState.fieldErrors.email[0]}</p>
101
+ )}
102
+ </div>
103
+ <div>
104
+ <Label htmlFor="password">Password</Label>
105
+ <Input
106
+ id="password"
107
+ name="password"
108
+ type="password"
109
+ value={password}
110
+ onChange={(e) => setPassword(e.target.value)}
111
+ placeholder="Enter your password"
112
+ required
113
+ disabled={loading}
114
+ />
115
+ {actionState?.fieldErrors?.password && (
116
+ <p className="text-sm text-red-600 mt-1">{actionState.fieldErrors.password[0]}</p>
117
+ )}
118
+ </div>
119
+ <Button type="submit" className="w-full" disabled={loading}>
120
+ {loading ? 'Signing In...' : 'Sign In'}
121
+ </Button>
122
+ <Button
123
+ type="button"
124
+ variant="outline"
125
+ className="w-full"
126
+ onClick={handleGoogleLogin}
127
+ disabled={loading}
128
+ >
129
+ Sign in with Google
130
+ </Button>
131
+ </form>
132
+
133
+ <div className="mt-4 text-center">
134
+ <p className="text-sm text-gray-600 dark:text-gray-300">
135
+ Don&apos;t have an account?{' '}
136
+ <a href="/signup" className="text-blue-600 hover:underline dark:text-blue-400">
137
+ Sign up
138
+ </a>
139
+ </p>
140
+ </div>
141
+ </Card>
142
+ </div>
143
+ )
144
+ }