@digilogiclabs/create-saas-app 2.8.1 → 2.9.1
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/generators/template-generator.js +8 -8
- package/dist/generators/template-generator.js.map +1 -1
- package/dist/templates/shared/quality/web/src/__tests__/accessibility.test.tsx +3 -3
- package/dist/templates/web/ai-platform/template/src/app/page.tsx +207 -207
- package/dist/templates/web/ai-platform/template/src/components/providers/app-providers.tsx +5 -2
- package/dist/templates/web/base/template/src/app/dashboard/page.tsx +6 -43
- package/dist/templates/web/base/template/src/app/page.tsx +2 -2
- package/dist/templates/web/base/template/src/components/providers/app-providers.tsx +5 -2
- package/dist/templates/web/iot-dashboard/template/src/components/providers/app-providers.tsx +5 -2
- package/dist/templates/web/marketplace/template/src/components/providers/app-providers.tsx +5 -2
- package/dist/templates/web/micro-saas/template/src/components/providers/app-providers.tsx +5 -2
- package/dist/templates/web/ui-auth/template/src/app/dev-setup/page.tsx +800 -800
- package/dist/templates/web/ui-auth/template/src/app/login/page.tsx +109 -109
- package/dist/templates/web/ui-auth/template/src/app/page.tsx +3 -3
- package/dist/templates/web/ui-auth/template/src/app/signup/page.tsx +128 -128
- package/dist/templates/web/ui-auth/template/src/components/providers/app-providers.tsx +5 -2
- package/dist/templates/web/ui-auth-ai/template/src/app/globals.css +35 -40
- package/dist/templates/web/ui-auth-ai/template/src/app/layout.tsx +1 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/checkout/page.tsx +3 -3
- package/dist/templates/web/ui-auth-payments/template/src/app/dashboard/page.tsx +10 -49
- package/dist/templates/web/ui-auth-payments/template/src/app/dev-setup/page.tsx +800 -800
- package/dist/templates/web/ui-auth-payments/template/src/app/login/page.tsx +109 -109
- package/dist/templates/web/ui-auth-payments/template/src/app/page.tsx +350 -350
- package/dist/templates/web/ui-auth-payments/template/src/app/setup/page.tsx +506 -506
- package/dist/templates/web/ui-auth-payments/template/src/app/signup/page.tsx +128 -128
- package/dist/templates/web/ui-auth-payments/template/src/components/client/login-form.tsx +143 -143
- package/dist/templates/web/ui-auth-payments/template/src/components/client/signup-form.tsx +184 -184
- package/dist/templates/web/ui-auth-payments-ai/template/src/app/billing/page.tsx +143 -233
- package/dist/templates/web/ui-auth-payments-ai/template/src/app/dashboard/page.tsx +10 -50
- package/dist/templates/web/ui-auth-payments-ai/template/src/app/dev-setup/page.tsx +800 -800
- package/dist/templates/web/ui-auth-payments-ai/template/src/app/onboarding/page.tsx +325 -364
- package/dist/templates/web/ui-auth-payments-ai/template/src/app/page.tsx +1 -1
- package/dist/templates/web/ui-auth-payments-ai/template/src/app/settings/page.tsx +389 -532
- package/dist/templates/web/ui-auth-payments-ai/template/src/app/setup/page.tsx +644 -644
- package/dist/templates/web/ui-auth-payments-ai/template/src/components/client/login-form.tsx +119 -163
- package/dist/templates/web/ui-auth-payments-ai/template/src/components/client/signup-form.tsx +158 -201
- package/dist/templates/web/ui-auth-payments-ai/template/src/components/providers/app-providers.tsx +5 -2
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/dashboard/page.tsx +10 -51
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/page.tsx +402 -403
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/client/login-form.tsx +143 -143
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/client/signup-form.tsx +184 -184
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/providers/app-providers.tsx +5 -2
- package/dist/templates/web/ui-auth-payments-video/template/src/app/login/page.tsx +1 -1
- package/dist/templates/web/ui-auth-payments-video/template/src/app/page.tsx +3 -7
- package/dist/templates/web/ui-auth-payments-video/template/src/app/signup/page.tsx +1 -1
- package/dist/templates/web/ui-auth-payments-video/template/src/components/providers/app-providers.tsx +5 -2
- package/dist/templates/web/ui-only/template/src/components/providers/app-providers.tsx +20 -26
- package/package.json +1 -1
- package/src/templates/shared/quality/web/src/__tests__/accessibility.test.tsx +3 -3
- package/src/templates/web/ai-platform/template/src/app/page.tsx +207 -207
- package/src/templates/web/ai-platform/template/src/components/providers/app-providers.tsx +5 -2
- package/src/templates/web/base/template/src/app/dashboard/page.tsx +6 -43
- package/src/templates/web/base/template/src/app/page.tsx +2 -2
- package/src/templates/web/base/template/src/components/providers/app-providers.tsx +5 -2
- package/src/templates/web/iot-dashboard/template/src/components/providers/app-providers.tsx +5 -2
- package/src/templates/web/marketplace/template/src/components/providers/app-providers.tsx +5 -2
- package/src/templates/web/micro-saas/template/src/components/providers/app-providers.tsx +5 -2
- package/src/templates/web/ui-auth/template/src/app/dev-setup/page.tsx +800 -800
- package/src/templates/web/ui-auth/template/src/app/login/page.tsx +109 -109
- package/src/templates/web/ui-auth/template/src/app/page.tsx +3 -3
- package/src/templates/web/ui-auth/template/src/app/signup/page.tsx +128 -128
- package/src/templates/web/ui-auth/template/src/components/providers/app-providers.tsx +5 -2
- package/src/templates/web/ui-auth-ai/template/src/app/globals.css +35 -40
- package/src/templates/web/ui-auth-ai/template/src/app/layout.tsx +1 -0
- package/src/templates/web/ui-auth-payments/template/src/app/checkout/page.tsx +3 -3
- package/src/templates/web/ui-auth-payments/template/src/app/dashboard/page.tsx +10 -49
- package/src/templates/web/ui-auth-payments/template/src/app/dev-setup/page.tsx +800 -800
- package/src/templates/web/ui-auth-payments/template/src/app/login/page.tsx +109 -109
- package/src/templates/web/ui-auth-payments/template/src/app/page.tsx +350 -350
- package/src/templates/web/ui-auth-payments/template/src/app/setup/page.tsx +506 -506
- package/src/templates/web/ui-auth-payments/template/src/app/signup/page.tsx +128 -128
- package/src/templates/web/ui-auth-payments/template/src/components/client/login-form.tsx +143 -143
- package/src/templates/web/ui-auth-payments/template/src/components/client/signup-form.tsx +184 -184
- package/src/templates/web/ui-auth-payments-ai/template/src/app/billing/page.tsx +143 -233
- package/src/templates/web/ui-auth-payments-ai/template/src/app/dashboard/page.tsx +10 -50
- package/src/templates/web/ui-auth-payments-ai/template/src/app/dev-setup/page.tsx +800 -800
- package/src/templates/web/ui-auth-payments-ai/template/src/app/onboarding/page.tsx +325 -364
- package/src/templates/web/ui-auth-payments-ai/template/src/app/page.tsx +1 -1
- package/src/templates/web/ui-auth-payments-ai/template/src/app/settings/page.tsx +389 -532
- package/src/templates/web/ui-auth-payments-ai/template/src/app/setup/page.tsx +644 -644
- package/src/templates/web/ui-auth-payments-ai/template/src/components/client/login-form.tsx +119 -163
- package/src/templates/web/ui-auth-payments-ai/template/src/components/client/signup-form.tsx +158 -201
- package/src/templates/web/ui-auth-payments-ai/template/src/components/providers/app-providers.tsx +5 -2
- package/src/templates/web/ui-auth-payments-audio/template/src/app/dashboard/page.tsx +10 -51
- package/src/templates/web/ui-auth-payments-audio/template/src/app/page.tsx +402 -403
- package/src/templates/web/ui-auth-payments-audio/template/src/components/client/login-form.tsx +143 -143
- package/src/templates/web/ui-auth-payments-audio/template/src/components/client/signup-form.tsx +184 -184
- package/src/templates/web/ui-auth-payments-audio/template/src/components/providers/app-providers.tsx +5 -2
- package/src/templates/web/ui-auth-payments-video/template/src/app/login/page.tsx +1 -1
- package/src/templates/web/ui-auth-payments-video/template/src/app/page.tsx +3 -7
- package/src/templates/web/ui-auth-payments-video/template/src/app/signup/page.tsx +1 -1
- package/src/templates/web/ui-auth-payments-video/template/src/components/providers/app-providers.tsx +5 -2
- package/src/templates/web/ui-only/template/src/components/providers/app-providers.tsx +20 -26
|
@@ -1,128 +1,128 @@
|
|
|
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/app-sdk';
|
|
6
|
-
import { useRouter } from 'next/navigation';
|
|
7
|
-
|
|
8
|
-
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'
|
|
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
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
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/app-sdk';
|
|
6
|
+
import { useRouter } from 'next/navigation';
|
|
7
|
+
|
|
8
|
+
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');
|
|
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
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
@@ -1,144 +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/app-sdk'
|
|
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'
|
|
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'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
|
-
)
|
|
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/app-sdk'
|
|
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')
|
|
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'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
144
|
}
|