@liedsonc/core-auth-kit 0.1.0 → 0.2.0

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 (35) hide show
  1. package/README.md +802 -759
  2. package/auth-ui/bin/init.js +126 -0
  3. package/auth-ui/components/auth-card.tsx +49 -49
  4. package/auth-ui/components/auth-form.tsx +53 -53
  5. package/auth-ui/components/error-message.tsx +24 -24
  6. package/auth-ui/components/form-field.tsx +39 -39
  7. package/auth-ui/components/loading-spinner.tsx +19 -19
  8. package/auth-ui/components/oauth-buttons.tsx +49 -49
  9. package/auth-ui/components/password-input.tsx +93 -93
  10. package/auth-ui/components/success-message.tsx +24 -24
  11. package/auth-ui/package.json +61 -55
  12. package/auth-ui/pages/forgot-password/index.tsx +83 -83
  13. package/auth-ui/pages/login/index.tsx +119 -119
  14. package/auth-ui/pages/register/index.tsx +149 -149
  15. package/auth-ui/pages/reset-password/index.tsx +133 -133
  16. package/auth-ui/pages/verify-email/index.tsx +143 -143
  17. package/auth-ui/templates/app/(auth)/forgot-password/page.tsx +5 -0
  18. package/auth-ui/templates/app/(auth)/layout.tsx +12 -0
  19. package/auth-ui/templates/app/(auth)/login/page.tsx +5 -0
  20. package/auth-ui/templates/app/(auth)/register/page.tsx +5 -0
  21. package/auth-ui/templates/app/(auth)/reset-password/page.tsx +5 -0
  22. package/auth-ui/templates/app/(auth)/verify-email/page.tsx +5 -0
  23. package/auth-ui/templates/app/api/auth/forgot-password/route.ts +16 -0
  24. package/auth-ui/templates/app/api/auth/login/route.ts +16 -0
  25. package/auth-ui/templates/app/api/auth/logout/route.ts +8 -0
  26. package/auth-ui/templates/app/api/auth/register/route.ts +16 -0
  27. package/auth-ui/templates/app/api/auth/reset-password/route.ts +16 -0
  28. package/auth-ui/templates/app/api/auth/session/route.ts +8 -0
  29. package/auth-ui/templates/app/api/auth/verify-email/route.ts +16 -0
  30. package/auth-ui/templates/env.example +25 -0
  31. package/auth-ui/templates/lib/auth-client.ts +20 -0
  32. package/auth-ui/templates/lib/auth-config.ts +43 -0
  33. package/auth-ui/tsconfig.json +4 -15
  34. package/package.json +17 -6
  35. package/tailwind.config.ts +41 -41
@@ -1,93 +1,93 @@
1
- "use client";
2
-
3
- import * as React from "react";
4
- import { Input } from "./ui/input";
5
- import { Button } from "./ui/button";
6
- import { cn } from "../utils";
7
-
8
- function getStrength(value: string): 0 | 1 | 2 | 3 {
9
- if (!value) return 0;
10
- let s = 0;
11
- if (value.length >= 8) s++;
12
- if (value.length >= 12) s++;
13
- if (/[A-Z]/.test(value) && /[a-z]/.test(value) && /\d/.test(value)) s++;
14
- return Math.min(s, 3) as 0 | 1 | 2 | 3;
15
- }
16
-
17
- export interface PasswordInputProps
18
- extends Omit<React.ComponentProps<typeof Input>, "type"> {
19
- showStrength?: boolean;
20
- }
21
-
22
- const PasswordInput = React.forwardRef<HTMLInputElement, PasswordInputProps>(
23
- ({ className, showStrength = false, ...props }, ref) => {
24
- const [show, setShow] = React.useState(false);
25
- const [value, setValue] = React.useState("");
26
- const id = React.useId();
27
- const strength = showStrength ? getStrength(value) : 0;
28
-
29
- return (
30
- <div className="space-y-1.5">
31
- <div className="relative">
32
- <Input
33
- ref={ref}
34
- type={show ? "text" : "password"}
35
- autoComplete="current-password"
36
- aria-describedby={showStrength ? `${id}-strength` : undefined}
37
- className={cn("pr-10", className)}
38
- {...props}
39
- value={props.value ?? value}
40
- onChange={(e) => {
41
- setValue(e.target.value);
42
- props.onChange?.(e);
43
- }}
44
- />
45
- <Button
46
- type="button"
47
- variant="ghost"
48
- size="icon"
49
- className="absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent"
50
- aria-label={show ? "Hide password" : "Show password"}
51
- aria-pressed={show}
52
- onClick={() => setShow((p) => !p)}
53
- tabIndex={-1}
54
- >
55
- <span className="text-xs font-medium" aria-hidden="true">
56
- {show ? "Hide" : "Show"}
57
- </span>
58
- </Button>
59
- </div>
60
- {showStrength && value && (
61
- <div
62
- id={`${id}-strength`}
63
- role="progressbar"
64
- aria-valuenow={strength}
65
- aria-valuemin={0}
66
- aria-valuemax={3}
67
- aria-label="Password strength"
68
- className="flex gap-1"
69
- >
70
- {[1, 2, 3].map((i) => (
71
- <span
72
- key={i}
73
- className={cn(
74
- "h-1 flex-1 rounded-full",
75
- i <= strength
76
- ? strength === 1
77
- ? "bg-destructive"
78
- : strength === 2
79
- ? "bg-amber-500"
80
- : "bg-green-500"
81
- : "bg-muted"
82
- )}
83
- />
84
- ))}
85
- </div>
86
- )}
87
- </div>
88
- );
89
- }
90
- );
91
- PasswordInput.displayName = "PasswordInput";
92
-
93
- export { PasswordInput };
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { Input } from "./ui/input";
5
+ import { Button } from "./ui/button";
6
+ import { cn } from "../utils";
7
+
8
+ function getStrength(value: string): 0 | 1 | 2 | 3 {
9
+ if (!value) return 0;
10
+ let s = 0;
11
+ if (value.length >= 8) s++;
12
+ if (value.length >= 12) s++;
13
+ if (/[A-Z]/.test(value) && /[a-z]/.test(value) && /\d/.test(value)) s++;
14
+ return Math.min(s, 3) as 0 | 1 | 2 | 3;
15
+ }
16
+
17
+ export interface PasswordInputProps
18
+ extends Omit<React.ComponentProps<typeof Input>, "type"> {
19
+ showStrength?: boolean;
20
+ }
21
+
22
+ const PasswordInput = React.forwardRef<HTMLInputElement, PasswordInputProps>(
23
+ ({ className, showStrength = false, ...props }, ref) => {
24
+ const [show, setShow] = React.useState(false);
25
+ const [value, setValue] = React.useState("");
26
+ const id = React.useId();
27
+ const strength = showStrength ? getStrength(value) : 0;
28
+
29
+ return (
30
+ <div className="space-y-1.5">
31
+ <div className="relative">
32
+ <Input
33
+ ref={ref}
34
+ type={show ? "text" : "password"}
35
+ autoComplete="current-password"
36
+ aria-describedby={showStrength ? `${id}-strength` : undefined}
37
+ className={cn("pr-10", className)}
38
+ {...props}
39
+ value={props.value ?? value}
40
+ onChange={(e) => {
41
+ setValue(e.target.value);
42
+ props.onChange?.(e);
43
+ }}
44
+ />
45
+ <Button
46
+ type="button"
47
+ variant="ghost"
48
+ size="icon"
49
+ className="absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent"
50
+ aria-label={show ? "Hide password" : "Show password"}
51
+ aria-pressed={show}
52
+ onClick={() => setShow((p) => !p)}
53
+ tabIndex={-1}
54
+ >
55
+ <span className="text-xs font-medium" aria-hidden="true">
56
+ {show ? "Hide" : "Show"}
57
+ </span>
58
+ </Button>
59
+ </div>
60
+ {showStrength && value && (
61
+ <div
62
+ id={`${id}-strength`}
63
+ role="progressbar"
64
+ aria-valuenow={strength}
65
+ aria-valuemin={0}
66
+ aria-valuemax={3}
67
+ aria-label="Password strength"
68
+ className="flex gap-1"
69
+ >
70
+ {[1, 2, 3].map((i) => (
71
+ <span
72
+ key={i}
73
+ className={cn(
74
+ "h-1 flex-1 rounded-full",
75
+ i <= strength
76
+ ? strength === 1
77
+ ? "bg-destructive"
78
+ : strength === 2
79
+ ? "bg-amber-500"
80
+ : "bg-green-500"
81
+ : "bg-muted"
82
+ )}
83
+ />
84
+ ))}
85
+ </div>
86
+ )}
87
+ </div>
88
+ );
89
+ }
90
+ );
91
+ PasswordInput.displayName = "PasswordInput";
92
+
93
+ export { PasswordInput };
@@ -1,24 +1,24 @@
1
- "use client";
2
-
3
- import { cn } from "../utils";
4
-
5
- export function SuccessMessage({
6
- children,
7
- className,
8
- id,
9
- }: {
10
- children: React.ReactNode;
11
- className?: string;
12
- id?: string;
13
- }) {
14
- if (!children) return null;
15
- return (
16
- <p
17
- id={id}
18
- role="status"
19
- className={cn("text-sm text-green-600 dark:text-green-400", className)}
20
- >
21
- {children}
22
- </p>
23
- );
24
- }
1
+ "use client";
2
+
3
+ import { cn } from "../utils";
4
+
5
+ export function SuccessMessage({
6
+ children,
7
+ className,
8
+ id,
9
+ }: {
10
+ children: React.ReactNode;
11
+ className?: string;
12
+ id?: string;
13
+ }) {
14
+ if (!children) return null;
15
+ return (
16
+ <p
17
+ id={id}
18
+ role="status"
19
+ className={cn("text-sm text-green-600 dark:text-green-400", className)}
20
+ >
21
+ {children}
22
+ </p>
23
+ );
24
+ }
@@ -1,55 +1,61 @@
1
- {
2
- "name": "@liedsonc/core-auth-kit",
3
- "version": "0.1.0",
4
- "description": "Production-ready authentication UI package for Next.js App Router",
5
- "main": "./index.ts",
6
- "types": "./index.ts",
7
- "exports": {
8
- ".": "./index.ts",
9
- "./styles": "./styles/index.css"
10
- },
11
- "files": [
12
- "**/*.ts",
13
- "**/*.tsx",
14
- "**/*.css"
15
- ],
16
- "scripts": {
17
- "build": "tsc --noEmit",
18
- "type-check": "tsc --noEmit"
19
- },
20
- "dependencies": {
21
- "@radix-ui/react-label": "^2.1.0",
22
- "@radix-ui/react-slot": "^1.1.0",
23
- "class-variance-authority": "^0.7.0",
24
- "clsx": "^2.1.1",
25
- "tailwind-merge": "^2.5.0"
26
- },
27
- "peerDependencies": {
28
- "next": "^15.0.0",
29
- "react": "^19.0.0",
30
- "react-dom": "^19.0.0"
31
- },
32
- "devDependencies": {
33
- "@types/react": "^19.0.0",
34
- "typescript": "^5.6.0"
35
- },
36
- "keywords": [
37
- "nextjs",
38
- "auth",
39
- "authentication",
40
- "ui",
41
- "shadcn",
42
- "react",
43
- "typescript"
44
- ],
45
- "license": "MIT",
46
- "repository": {
47
- "type": "git",
48
- "url": "https://github.com/liedsonc/core-auth-kit.git",
49
- "directory": "auth-ui"
50
- },
51
- "bugs": {
52
- "url": "https://github.com/liedsonc/core-auth-kit/issues"
53
- },
54
- "homepage": "https://github.com/liedsonc/core-auth-kit#readme"
55
- }
1
+ {
2
+ "name": "@liedsonc/core-auth-kit",
3
+ "version": "0.1.0",
4
+ "description": "Production-ready authentication UI package for Next.js App Router",
5
+ "main": "./index.ts",
6
+ "types": "./index.ts",
7
+ "exports": {
8
+ ".": "./index.ts",
9
+ "./styles": "./styles/index.css"
10
+ },
11
+ "bin": {
12
+ "core-auth-kit": "bin/init.js"
13
+ },
14
+ "files": [
15
+ "**/*.ts",
16
+ "**/*.tsx",
17
+ "**/*.css",
18
+ "**/*.js",
19
+ "templates"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc --noEmit",
23
+ "type-check": "tsc --noEmit",
24
+ "publish": "npm publish --access public"
25
+ },
26
+ "dependencies": {
27
+ "@radix-ui/react-label": "^2.1.0",
28
+ "@radix-ui/react-slot": "^1.1.0",
29
+ "class-variance-authority": "^0.7.0",
30
+ "clsx": "^2.1.1",
31
+ "tailwind-merge": "^2.5.0"
32
+ },
33
+ "peerDependencies": {
34
+ "next": "^15.0.0",
35
+ "react": "^19.0.0",
36
+ "react-dom": "^19.0.0"
37
+ },
38
+ "devDependencies": {
39
+ "@types/react": "^19.0.0",
40
+ "typescript": "^5.6.0"
41
+ },
42
+ "keywords": [
43
+ "nextjs",
44
+ "auth",
45
+ "authentication",
46
+ "ui",
47
+ "shadcn",
48
+ "react",
49
+ "typescript"
50
+ ],
51
+ "license": "MIT",
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "git+https://github.com/liedsonc/core-auth-kit.git",
55
+ "directory": "auth-ui"
56
+ },
57
+ "bugs": {
58
+ "url": "https://github.com/liedsonc/core-auth-kit/issues"
59
+ },
60
+ "homepage": "https://github.com/liedsonc/core-auth-kit#readme"
61
+ }
@@ -1,83 +1,83 @@
1
- "use client";
2
-
3
- import Link from "next/link";
4
- import { useAuth } from "../../hooks/use-auth";
5
- import { AuthCard } from "../../components/auth-card";
6
- import { AuthForm } from "../../components/auth-form";
7
- import { FormField } from "../../components/form-field";
8
- import { SuccessMessage } from "../../components/success-message";
9
- import { Button } from "../../components/ui/button";
10
- import { Input } from "../../components/ui/input";
11
- import { useState } from "react";
12
-
13
- const successMessage =
14
- "If an account exists for this email, you will receive a link to reset your password.";
15
-
16
- export function ForgotPasswordPage() {
17
- const { forgotPassword, loading, error, clearError } = useAuth();
18
- const [email, setEmail] = useState("");
19
- const [submitted, setSubmitted] = useState(false);
20
- const [fieldError, setFieldError] = useState<string | undefined>();
21
-
22
- const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
23
- e.preventDefault();
24
- clearError();
25
- setFieldError(undefined);
26
- if (!email.trim()) {
27
- setFieldError("Email is required.");
28
- return;
29
- }
30
- await forgotPassword(email.trim());
31
- setSubmitted(true);
32
- };
33
-
34
- return (
35
- <div className="flex min-h-screen flex-col items-center justify-center p-4">
36
- <AuthCard
37
- title="Forgot password"
38
- subtitle="Enter your email and we'll send you a reset link"
39
- footer={
40
- <div className="flex w-full justify-center text-sm text-muted-foreground">
41
- <Link
42
- href="/login"
43
- className="underline underline-offset-4 hover:text-foreground"
44
- >
45
- Back to sign in
46
- </Link>
47
- </div>
48
- }
49
- >
50
- {submitted ? (
51
- <SuccessMessage>{successMessage}</SuccessMessage>
52
- ) : (
53
- <AuthForm onSubmit={handleSubmit} loading={loading}>
54
- {error && (
55
- <p role="alert" className="text-sm text-destructive">
56
- Something went wrong. Please try again later.
57
- </p>
58
- )}
59
- <FormField label="Email" htmlFor="forgot-email" error={fieldError} required>
60
- <Input
61
- id="forgot-email"
62
- type="email"
63
- autoComplete="email"
64
- placeholder="you@example.com"
65
- value={email}
66
- onChange={(e) => setEmail(e.target.value)}
67
- disabled={loading}
68
- aria-invalid={!!fieldError}
69
- />
70
- </FormField>
71
- <Button type="submit" className="w-full" disabled={loading}>
72
- {loading ? (
73
- <span className="inline-block size-4 animate-spin rounded-full border-2 border-current border-t-transparent" />
74
- ) : (
75
- "Send reset link"
76
- )}
77
- </Button>
78
- </AuthForm>
79
- )}
80
- </AuthCard>
81
- </div>
82
- );
83
- }
1
+ "use client";
2
+
3
+ import Link from "next/link";
4
+ import { useAuth } from "../../hooks/use-auth";
5
+ import { AuthCard } from "../../components/auth-card";
6
+ import { AuthForm } from "../../components/auth-form";
7
+ import { FormField } from "../../components/form-field";
8
+ import { SuccessMessage } from "../../components/success-message";
9
+ import { Button } from "../../components/ui/button";
10
+ import { Input } from "../../components/ui/input";
11
+ import { useState } from "react";
12
+
13
+ const successMessage =
14
+ "If an account exists for this email, you will receive a link to reset your password.";
15
+
16
+ export function ForgotPasswordPage() {
17
+ const { forgotPassword, loading, error, clearError } = useAuth();
18
+ const [email, setEmail] = useState("");
19
+ const [submitted, setSubmitted] = useState(false);
20
+ const [fieldError, setFieldError] = useState<string | undefined>();
21
+
22
+ const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
23
+ e.preventDefault();
24
+ clearError();
25
+ setFieldError(undefined);
26
+ if (!email.trim()) {
27
+ setFieldError("Email is required.");
28
+ return;
29
+ }
30
+ await forgotPassword(email.trim());
31
+ setSubmitted(true);
32
+ };
33
+
34
+ return (
35
+ <div className="flex min-h-screen flex-col items-center justify-center p-4">
36
+ <AuthCard
37
+ title="Forgot password"
38
+ subtitle="Enter your email and we'll send you a reset link"
39
+ footer={
40
+ <div className="flex w-full justify-center text-sm text-muted-foreground">
41
+ <Link
42
+ href="/login"
43
+ className="underline underline-offset-4 hover:text-foreground"
44
+ >
45
+ Back to sign in
46
+ </Link>
47
+ </div>
48
+ }
49
+ >
50
+ {submitted ? (
51
+ <SuccessMessage>{successMessage}</SuccessMessage>
52
+ ) : (
53
+ <AuthForm onSubmit={handleSubmit} loading={loading}>
54
+ {error && (
55
+ <p role="alert" className="text-sm text-destructive">
56
+ Something went wrong. Please try again later.
57
+ </p>
58
+ )}
59
+ <FormField label="Email" htmlFor="forgot-email" error={fieldError} required>
60
+ <Input
61
+ id="forgot-email"
62
+ type="email"
63
+ autoComplete="email"
64
+ placeholder="you@example.com"
65
+ value={email}
66
+ onChange={(e) => setEmail(e.target.value)}
67
+ disabled={loading}
68
+ aria-invalid={!!fieldError}
69
+ />
70
+ </FormField>
71
+ <Button type="submit" className="w-full" disabled={loading}>
72
+ {loading ? (
73
+ <span className="inline-block size-4 animate-spin rounded-full border-2 border-current border-t-transparent" />
74
+ ) : (
75
+ "Send reset link"
76
+ )}
77
+ </Button>
78
+ </AuthForm>
79
+ )}
80
+ </AuthCard>
81
+ </div>
82
+ );
83
+ }