@main12/auth-login 0.3.4 → 0.3.6
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/components/AuthPagesServer.d.ts +4 -2
- package/dist/components/AuthPagesServer.js +10 -12
- package/dist/components/pages/LoginPageHero.js +1 -0
- package/dist/components/pages/SignupPageHero.js +2 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.js +2 -1
- package/dist/endpoints/authEndpoints.js +2 -1
- package/dist/index.js +4 -8
- package/dist/proxy.js +2 -2
- package/package.json +53 -17
|
@@ -2,8 +2,10 @@ import type { AuthPagesProps } from './AuthPages';
|
|
|
2
2
|
export type { AuthPagesProps };
|
|
3
3
|
/**
|
|
4
4
|
* Server component wrapper for AuthPages.
|
|
5
|
-
* Reads plugin config
|
|
6
|
-
*
|
|
5
|
+
* Reads plugin config directly from the shared `pluginConfig` singleton
|
|
6
|
+
* (set by the plugin factory at Payload config build time) and passes it
|
|
7
|
+
* down to the client component. No env vars involved — the plugin's
|
|
8
|
+
* `style`, `googleOAuthEnabled`, etc. options are the single source of truth.
|
|
7
9
|
*
|
|
8
10
|
* ```tsx
|
|
9
11
|
* // app/(auth)/auth/[...slug]/page.tsx (NO 'use client' needed!)
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import AuthPagesClient from './AuthPages.js';
|
|
3
|
+
import { pluginConfig } from '../config.js';
|
|
3
4
|
/**
|
|
4
5
|
* Server component wrapper for AuthPages.
|
|
5
|
-
* Reads plugin config
|
|
6
|
-
*
|
|
6
|
+
* Reads plugin config directly from the shared `pluginConfig` singleton
|
|
7
|
+
* (set by the plugin factory at Payload config build time) and passes it
|
|
8
|
+
* down to the client component. No env vars involved — the plugin's
|
|
9
|
+
* `style`, `googleOAuthEnabled`, etc. options are the single source of truth.
|
|
7
10
|
*
|
|
8
11
|
* ```tsx
|
|
9
12
|
* // app/(auth)/auth/[...slug]/page.tsx (NO 'use client' needed!)
|
|
@@ -14,17 +17,12 @@ import AuthPagesClient from './AuthPages.js';
|
|
|
14
17
|
* }
|
|
15
18
|
* ```
|
|
16
19
|
*/ export default function AuthPages(props) {
|
|
17
|
-
const googleOAuthEnabled = process.env.AUTH_PLUGIN_GOOGLE_OAUTH === 'true';
|
|
18
|
-
const style = process.env.AUTH_PLUGIN_STYLE || 'tailwind';
|
|
19
|
-
const allowSignup = process.env.AUTH_PLUGIN_ALLOW_SIGNUP !== 'false';
|
|
20
|
-
const passwordLogin = process.env.AUTH_PLUGIN_PASSWORD_LOGIN !== 'false';
|
|
21
|
-
const otpLogin = process.env.AUTH_PLUGIN_OTP_LOGIN !== 'false';
|
|
22
20
|
return /*#__PURE__*/ _jsx(AuthPagesClient, {
|
|
23
21
|
...props,
|
|
24
|
-
showGoogleOAuth: props.showGoogleOAuth ?? googleOAuthEnabled,
|
|
25
|
-
style: props.style ?? style,
|
|
26
|
-
allowSignup: props.allowSignup ?? allowSignup,
|
|
27
|
-
passwordLogin: passwordLogin,
|
|
28
|
-
otpLogin: otpLogin
|
|
22
|
+
showGoogleOAuth: props.showGoogleOAuth ?? pluginConfig.googleOAuthEnabled,
|
|
23
|
+
style: props.style ?? pluginConfig.style,
|
|
24
|
+
allowSignup: props.allowSignup ?? pluginConfig.allowSignup,
|
|
25
|
+
passwordLogin: pluginConfig.passwordLogin,
|
|
26
|
+
otpLogin: pluginConfig.otpLogin
|
|
29
27
|
});
|
|
30
28
|
}
|
|
@@ -61,6 +61,7 @@ function LoginHeroContent({ onPasswordLogin, redirectTo = '/', showGoogleOAuth =
|
|
|
61
61
|
fullWidth: true,
|
|
62
62
|
variant: "secondary",
|
|
63
63
|
onPress: handleGoogleLogin,
|
|
64
|
+
className: "[--button-fg:var(--foreground)]",
|
|
64
65
|
children: [
|
|
65
66
|
/*#__PURE__*/ _jsx(Icon, {
|
|
66
67
|
icon: "flat-color-icons:google",
|
|
@@ -49,8 +49,9 @@ export default function SignupPageHero({ onSignup, showGoogleOAuth = true, login
|
|
|
49
49
|
children: [
|
|
50
50
|
/*#__PURE__*/ _jsxs(Button, {
|
|
51
51
|
fullWidth: true,
|
|
52
|
+
variant: "secondary",
|
|
52
53
|
size: "lg",
|
|
53
|
-
className: "mb-4 h-12 rounded-full",
|
|
54
|
+
className: "mb-4 h-12 rounded-full [--button-fg:var(--foreground)]",
|
|
54
55
|
children: [
|
|
55
56
|
/*#__PURE__*/ _jsx(Icon, {
|
|
56
57
|
icon: "flat-color-icons:google",
|
package/dist/config.d.ts
CHANGED
package/dist/config.js
CHANGED
|
@@ -4,7 +4,8 @@ export const pluginConfig = {
|
|
|
4
4
|
routeRedirects: false,
|
|
5
5
|
authBasePath: '/auth',
|
|
6
6
|
passwordLogin: true,
|
|
7
|
-
otpLogin: true
|
|
7
|
+
otpLogin: true,
|
|
8
|
+
allowSignup: true
|
|
8
9
|
};
|
|
9
10
|
/** Call this client-side to mirror the server plugin config. */ export function initClientConfig(opts) {
|
|
10
11
|
if (opts.style) pluginConfig.style = opts.style;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import crypto from 'crypto';
|
|
2
2
|
import { generateOtp, hashOtp, verifyOtp, getOtpExpiry, isOtpExpired } from '../auth/domain/otp.js';
|
|
3
3
|
import { generateWelcomeEmail, generateOtpEmail } from '../components/email/index.js';
|
|
4
|
+
import { pluginConfig } from '../config.js';
|
|
4
5
|
/**
|
|
5
6
|
* POST /api/auth/check-email — Check if user exists and has password
|
|
6
7
|
*/ export const checkEmailEndpoint = {
|
|
@@ -352,7 +353,7 @@ import { generateWelcomeEmail, generateOtpEmail } from '../components/email/inde
|
|
|
352
353
|
path: '/auth/signup',
|
|
353
354
|
method: 'post',
|
|
354
355
|
handler: async (req)=>{
|
|
355
|
-
if (
|
|
356
|
+
if (!pluginConfig.allowSignup) {
|
|
356
357
|
return Response.json({
|
|
357
358
|
success: false,
|
|
358
359
|
message: 'Signups are currently disabled'
|
package/dist/index.js
CHANGED
|
@@ -53,7 +53,9 @@ export const authLoginPlugin = (options = {})=>async (config)=>{
|
|
|
53
53
|
// Resolve provider config
|
|
54
54
|
const googleConfig = resolveGoogleConfig(options.providers);
|
|
55
55
|
setOAuthEnv(googleConfig);
|
|
56
|
-
// Set global config — all components
|
|
56
|
+
// Set global config — all components (server and client) read this
|
|
57
|
+
// shared singleton directly at render time. This is the single source
|
|
58
|
+
// of truth; no env vars are used to propagate these settings.
|
|
57
59
|
pluginConfig.style = options.style || 'tailwind';
|
|
58
60
|
if (typeof options.logo === 'string') {
|
|
59
61
|
pluginConfig.logoUrl = options.logo;
|
|
@@ -61,15 +63,9 @@ export const authLoginPlugin = (options = {})=>async (config)=>{
|
|
|
61
63
|
pluginConfig.Logo = options.logo;
|
|
62
64
|
}
|
|
63
65
|
pluginConfig.googleOAuthEnabled = googleConfig.enabled;
|
|
64
|
-
|
|
65
|
-
process.env.AUTH_PLUGIN_STYLE = pluginConfig.style;
|
|
66
|
-
process.env.AUTH_PLUGIN_GOOGLE_OAUTH = String(pluginConfig.googleOAuthEnabled);
|
|
67
|
-
process.env.AUTH_PLUGIN_ALLOW_SIGNUP = String(options.allowSignup !== false);
|
|
68
|
-
process.env.AUTH_PLUGIN_PASSWORD_LOGIN = String(options.passwordLogin !== false);
|
|
69
|
-
process.env.AUTH_PLUGIN_OTP_LOGIN = String(options.otpLogin !== false);
|
|
66
|
+
pluginConfig.allowSignup = options.allowSignup !== false;
|
|
70
67
|
pluginConfig.passwordLogin = options.passwordLogin !== false;
|
|
71
68
|
pluginConfig.otpLogin = options.otpLogin !== false;
|
|
72
|
-
process.env.AUTH_PLUGIN_ROUTE_REDIRECTS = String(pluginConfig.routeRedirects);
|
|
73
69
|
// Route redirects config
|
|
74
70
|
if (options.routeRedirects) {
|
|
75
71
|
pluginConfig.routeRedirects = true;
|
package/dist/proxy.js
CHANGED
|
@@ -29,8 +29,8 @@ const AUTH_ROUTES = [
|
|
|
29
29
|
const base = (basePath ?? pluginConfig.authBasePath).replace(/\/$/, '');
|
|
30
30
|
const routeSet = new Set(routes);
|
|
31
31
|
return function proxy(request) {
|
|
32
|
-
// Check route redirects
|
|
33
|
-
const redirectsEnabled = pluginConfig.routeRedirects
|
|
32
|
+
// Check route redirects directly from the shared plugin config singleton
|
|
33
|
+
const redirectsEnabled = pluginConfig.routeRedirects;
|
|
34
34
|
if (!redirectsEnabled && !basePath) {
|
|
35
35
|
return NextResponse.next();
|
|
36
36
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@main12/auth-login",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Reusable Payload CMS auth plugin — login, signup, OTP, forgot password, branded emails, Powered by Main12",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
"import": "./dist/exports/rsc.js",
|
|
20
20
|
"types": "./dist/exports/rsc.d.ts",
|
|
21
21
|
"default": "./dist/exports/rsc.js"
|
|
22
|
+
},
|
|
23
|
+
"./proxy": {
|
|
24
|
+
"import": "./dist/proxy.js",
|
|
25
|
+
"types": "./dist/proxy.d.ts",
|
|
26
|
+
"default": "./dist/proxy.js"
|
|
22
27
|
}
|
|
23
28
|
},
|
|
24
29
|
"main": "./dist/index.js",
|
|
@@ -26,6 +31,21 @@
|
|
|
26
31
|
"files": [
|
|
27
32
|
"dist"
|
|
28
33
|
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "pnpm copyfiles && pnpm build:types && pnpm build:swc && pnpm build:fix-esm-imports",
|
|
36
|
+
"build:fix-esm-imports": "node ./scripts/fix-esm-imports.mjs",
|
|
37
|
+
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
38
|
+
"build:types": "tsc --outDir dist",
|
|
39
|
+
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
40
|
+
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
|
41
|
+
"dev": "next dev dev --turbo",
|
|
42
|
+
"dev:generate-importmap": "pnpm dev:payload generate:importmap",
|
|
43
|
+
"dev:generate-types": "pnpm dev:payload generate:types",
|
|
44
|
+
"dev:payload": "cross-env PAYLOAD_CONFIG_PATH=./dev/payload.config.ts payload",
|
|
45
|
+
"lint": "eslint",
|
|
46
|
+
"lint:fix": "eslint ./src --fix",
|
|
47
|
+
"test": "vitest"
|
|
48
|
+
},
|
|
29
49
|
"devDependencies": {
|
|
30
50
|
"@eslint/eslintrc": "^3.2.0",
|
|
31
51
|
"@heroui/react": "^3.2.2",
|
|
@@ -57,7 +77,10 @@
|
|
|
57
77
|
"vitest": "4.1.6"
|
|
58
78
|
},
|
|
59
79
|
"peerDependencies": {
|
|
80
|
+
"@heroui/react": ">=3.2.0",
|
|
81
|
+
"framer-motion": ">=12.0.0",
|
|
60
82
|
"next": "^16.0.0",
|
|
83
|
+
"next-intl": "*",
|
|
61
84
|
"payload": "^3.82.0",
|
|
62
85
|
"react": "^19.0.0"
|
|
63
86
|
},
|
|
@@ -75,26 +98,39 @@
|
|
|
75
98
|
"engines": {
|
|
76
99
|
"node": ">=18.20.2"
|
|
77
100
|
},
|
|
101
|
+
"publishConfig": {
|
|
102
|
+
"exports": {
|
|
103
|
+
".": {
|
|
104
|
+
"import": "./dist/index.js",
|
|
105
|
+
"types": "./dist/index.d.ts",
|
|
106
|
+
"default": "./dist/index.js"
|
|
107
|
+
},
|
|
108
|
+
"./client": {
|
|
109
|
+
"import": "./dist/exports/client.js",
|
|
110
|
+
"types": "./dist/exports/client.d.ts",
|
|
111
|
+
"default": "./dist/exports/client.js"
|
|
112
|
+
},
|
|
113
|
+
"./rsc": {
|
|
114
|
+
"import": "./dist/exports/rsc.js",
|
|
115
|
+
"types": "./dist/exports/rsc.d.ts",
|
|
116
|
+
"default": "./dist/exports/rsc.js"
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
"main": "./dist/index.js",
|
|
120
|
+
"types": "./dist/index.d.ts"
|
|
121
|
+
},
|
|
122
|
+
"pnpm": {
|
|
123
|
+
"onlyBuiltDependencies": [
|
|
124
|
+
"@swc/core",
|
|
125
|
+
"sharp",
|
|
126
|
+
"esbuild"
|
|
127
|
+
]
|
|
128
|
+
},
|
|
78
129
|
"registry": "https://registry.npmjs.org/",
|
|
79
130
|
"dependencies": {
|
|
80
131
|
"@main12/brevo-adapter": "^0.1.1",
|
|
81
132
|
"axios": "^1.20.0",
|
|
82
133
|
"jose": "^6.2.12",
|
|
83
134
|
"payload-oauth2": "^1.0.21"
|
|
84
|
-
},
|
|
85
|
-
"scripts": {
|
|
86
|
-
"build": "pnpm copyfiles && pnpm build:types && pnpm build:swc && pnpm build:fix-esm-imports",
|
|
87
|
-
"build:fix-esm-imports": "node ./scripts/fix-esm-imports.mjs",
|
|
88
|
-
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
89
|
-
"build:types": "tsc --outDir dist",
|
|
90
|
-
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
91
|
-
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
|
92
|
-
"dev": "next dev dev --turbo",
|
|
93
|
-
"dev:generate-importmap": "pnpm dev:payload generate:importmap",
|
|
94
|
-
"dev:generate-types": "pnpm dev:payload generate:types",
|
|
95
|
-
"dev:payload": "cross-env PAYLOAD_CONFIG_PATH=./dev/payload.config.ts payload",
|
|
96
|
-
"lint": "eslint",
|
|
97
|
-
"lint:fix": "eslint ./src --fix",
|
|
98
|
-
"test": "vitest"
|
|
99
135
|
}
|
|
100
|
-
}
|
|
136
|
+
}
|