@greatapps/greatauth-ui 0.3.0 → 0.3.2
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/index.d.ts +1 -0
- package/dist/index.js +66 -150
- package/dist/index.js.map +1 -1
- package/dist/ui.d.ts +1 -1
- package/dist/ui.js +2 -0
- package/dist/ui.js.map +1 -1
- package/package.json +1 -1
- package/src/components/login-form.tsx +95 -56
- package/src/types/index.ts +1 -0
- package/src/ui.ts +2 -0
package/package.json
CHANGED
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import { useRouter, useSearchParams } from "next/navigation";
|
|
5
|
-
import { Loader2 } from "lucide-react";
|
|
5
|
+
import { Loader2, Mail, Lock, AlertCircle } from "lucide-react";
|
|
6
6
|
import type { LoginFormConfig } from "../types";
|
|
7
7
|
import { authClient } from "../auth";
|
|
8
8
|
import { Button } from "./ui/button";
|
|
9
9
|
import { Input } from "./ui/input";
|
|
10
10
|
import { Label } from "./ui/label";
|
|
11
|
-
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "./ui/card";
|
|
12
|
-
import { Alert, AlertDescription } from "./ui/alert";
|
|
13
11
|
import { Badge } from "./ui/badge";
|
|
12
|
+
import { cn } from "../lib/utils";
|
|
14
13
|
|
|
15
14
|
interface LoginFormProps {
|
|
16
15
|
config: LoginFormConfig;
|
|
@@ -46,7 +45,10 @@ export function LoginForm({ config }: LoginFormProps) {
|
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
if (config.onPostLoginSuccess) {
|
|
49
|
-
const gauthToken = (data as
|
|
48
|
+
const gauthToken = (data as Record<string, unknown>)?.user
|
|
49
|
+
? ((data as Record<string, unknown>).user as Record<string, unknown>)
|
|
50
|
+
?.gauthToken as string | undefined
|
|
51
|
+
: undefined;
|
|
50
52
|
const redirectUrl = await config.onPostLoginSuccess(data?.user, gauthToken);
|
|
51
53
|
if (redirectUrl) {
|
|
52
54
|
router.push(redirectUrl);
|
|
@@ -62,60 +64,97 @@ export function LoginForm({ config }: LoginFormProps) {
|
|
|
62
64
|
};
|
|
63
65
|
|
|
64
66
|
return (
|
|
65
|
-
<div className="flex min-h-svh
|
|
66
|
-
<div className="w-full max-w-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
{config.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
67
|
+
<div className="flex min-h-svh items-center justify-center bg-muted/30 p-4">
|
|
68
|
+
<div className="w-full max-w-[400px]">
|
|
69
|
+
{/* Header */}
|
|
70
|
+
<div className="mb-8 text-center">
|
|
71
|
+
<div className="mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-xl bg-primary text-primary-foreground shadow-sm">
|
|
72
|
+
{config.icon}
|
|
73
|
+
</div>
|
|
74
|
+
<div className="flex items-center justify-center gap-2">
|
|
75
|
+
<h1 className="text-2xl font-semibold tracking-tight">
|
|
76
|
+
{config.appName}
|
|
77
|
+
</h1>
|
|
78
|
+
{config.appBadge && (
|
|
79
|
+
<Badge variant={config.appBadge.variant} className="text-xs">
|
|
80
|
+
{config.appBadge.text}
|
|
81
|
+
</Badge>
|
|
82
|
+
)}
|
|
83
|
+
</div>
|
|
84
|
+
<p className="mt-1.5 text-sm text-muted-foreground">
|
|
85
|
+
{config.description}
|
|
86
|
+
</p>
|
|
87
|
+
</div>
|
|
88
|
+
|
|
89
|
+
{/* Form Card */}
|
|
90
|
+
<div className="rounded-xl border bg-card p-6 shadow-sm">
|
|
91
|
+
<form onSubmit={handleSubmit} className="space-y-4">
|
|
92
|
+
{error && (
|
|
93
|
+
<div className="flex items-center gap-2 rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2.5 text-sm text-destructive">
|
|
94
|
+
<AlertCircle className="h-4 w-4 shrink-0" />
|
|
95
|
+
{error}
|
|
96
|
+
</div>
|
|
97
|
+
)}
|
|
98
|
+
|
|
99
|
+
<div className="space-y-1.5">
|
|
100
|
+
<Label htmlFor="login-email" className="text-sm font-medium">
|
|
101
|
+
Email
|
|
102
|
+
</Label>
|
|
103
|
+
<div className="relative">
|
|
104
|
+
<Mail className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
|
105
|
+
<Input
|
|
106
|
+
id="login-email"
|
|
107
|
+
type="email"
|
|
108
|
+
placeholder="email@exemplo.com"
|
|
109
|
+
value={email}
|
|
110
|
+
onChange={(e) => setEmail(e.target.value)}
|
|
111
|
+
className="pl-9"
|
|
112
|
+
autoComplete="email"
|
|
113
|
+
required
|
|
114
|
+
/>
|
|
115
|
+
</div>
|
|
79
116
|
</div>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
onChange={(e) => setEmail(e.target.value)}
|
|
98
|
-
required
|
|
99
|
-
/>
|
|
100
|
-
</div>
|
|
101
|
-
<div className="grid gap-2">
|
|
102
|
-
<Label htmlFor="password">Senha</Label>
|
|
103
|
-
<Input
|
|
104
|
-
id="password"
|
|
105
|
-
type="password"
|
|
106
|
-
value={password}
|
|
107
|
-
onChange={(e) => setPassword(e.target.value)}
|
|
108
|
-
required
|
|
109
|
-
/>
|
|
110
|
-
</div>
|
|
111
|
-
<Button type="submit" className="w-full" disabled={loading}>
|
|
112
|
-
{loading && <Loader2 className="animate-spin" />}
|
|
113
|
-
Entrar
|
|
114
|
-
</Button>
|
|
117
|
+
|
|
118
|
+
<div className="space-y-1.5">
|
|
119
|
+
<Label htmlFor="login-password" className="text-sm font-medium">
|
|
120
|
+
Senha
|
|
121
|
+
</Label>
|
|
122
|
+
<div className="relative">
|
|
123
|
+
<Lock className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
|
124
|
+
<Input
|
|
125
|
+
id="login-password"
|
|
126
|
+
type="password"
|
|
127
|
+
placeholder="••••••••"
|
|
128
|
+
value={password}
|
|
129
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
130
|
+
className="pl-9"
|
|
131
|
+
autoComplete="current-password"
|
|
132
|
+
required
|
|
133
|
+
/>
|
|
115
134
|
</div>
|
|
116
|
-
</
|
|
117
|
-
|
|
118
|
-
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
<Button
|
|
138
|
+
type="submit"
|
|
139
|
+
className={cn("w-full", loading && "cursor-wait")}
|
|
140
|
+
disabled={loading}
|
|
141
|
+
>
|
|
142
|
+
{loading ? (
|
|
143
|
+
<>
|
|
144
|
+
<Loader2 className="h-4 w-4 animate-spin" />
|
|
145
|
+
A entrar...
|
|
146
|
+
</>
|
|
147
|
+
) : (
|
|
148
|
+
"Entrar"
|
|
149
|
+
)}
|
|
150
|
+
</Button>
|
|
151
|
+
</form>
|
|
152
|
+
</div>
|
|
153
|
+
|
|
154
|
+
{/* Footer */}
|
|
155
|
+
<p className="mt-6 text-center text-xs text-muted-foreground">
|
|
156
|
+
{config.footerText || "Acesso restrito a utilizadores autorizados"}
|
|
157
|
+
</p>
|
|
119
158
|
</div>
|
|
120
159
|
</div>
|
|
121
160
|
);
|
package/src/types/index.ts
CHANGED
|
@@ -38,5 +38,6 @@ export interface LoginFormConfig {
|
|
|
38
38
|
appBadge?: { text: string; variant: "destructive" | "outline" };
|
|
39
39
|
description: string;
|
|
40
40
|
callbackUrlDefault: string;
|
|
41
|
+
footerText?: string;
|
|
41
42
|
onPostLoginSuccess?: (user: unknown, token?: string) => Promise<string | null>;
|
|
42
43
|
}
|