@main12/auth-login 0.1.7 → 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.
@@ -4,9 +4,13 @@ import { pluginConfig } from '../../config.js';
4
4
  import LoginPageTailwind from './LoginPageTailwind.js';
5
5
  import LoginPageHero from './LoginPageHero.js';
6
6
  export default function LoginPage(props) {
7
- return pluginConfig.style === 'hero-ui' ? /*#__PURE__*/ _jsx(LoginPageHero, {
7
+ const resolved = {
8
+ showGoogleOAuth: pluginConfig.googleOAuthEnabled,
8
9
  ...props
10
+ };
11
+ return pluginConfig.style === 'hero-ui' ? /*#__PURE__*/ _jsx(LoginPageHero, {
12
+ ...resolved
9
13
  }) : /*#__PURE__*/ _jsx(LoginPageTailwind, {
10
- ...props
14
+ ...resolved
11
15
  });
12
16
  }
@@ -4,9 +4,13 @@ import { pluginConfig } from '../../config.js';
4
4
  import SignupPageTailwind from './SignupPageTailwind.js';
5
5
  import SignupPageHero from './SignupPageHero.js';
6
6
  export default function SignupPage(props) {
7
- return pluginConfig.style === 'hero-ui' ? /*#__PURE__*/ _jsx(SignupPageHero, {
7
+ const resolved = {
8
+ showGoogleOAuth: pluginConfig.googleOAuthEnabled,
8
9
  ...props
10
+ };
11
+ return pluginConfig.style === 'hero-ui' ? /*#__PURE__*/ _jsx(SignupPageHero, {
12
+ ...resolved
9
13
  }) : /*#__PURE__*/ _jsx(SignupPageTailwind, {
10
- ...props
14
+ ...resolved
11
15
  });
12
16
  }
package/dist/config.d.ts CHANGED
@@ -6,4 +6,5 @@ export type AuthStyle = 'tailwind' | 'hero-ui';
6
6
  export declare const pluginConfig: {
7
7
  style: AuthStyle;
8
8
  logoUrl?: string;
9
+ googleOAuthEnabled: boolean;
9
10
  };
package/dist/config.js CHANGED
@@ -2,5 +2,6 @@
2
2
  * Shared plugin configuration — set by the plugin factory at init time,
3
3
  * read by all client components at render time.
4
4
  */ export const pluginConfig = {
5
- style: 'tailwind'
5
+ style: 'tailwind',
6
+ googleOAuthEnabled: true
6
7
  };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,16 @@
1
1
  import type { Config } from 'payload';
2
2
  import { pluginConfig, type AuthStyle } from './config.js';
3
+ export interface GoogleOAuthConfig {
4
+ /** Client ID from Google Cloud Console */
5
+ clientId?: string;
6
+ /** Client Secret from Google Cloud Console */
7
+ clientSecret?: string;
8
+ /** Toggle provider on/off */
9
+ enabled?: boolean;
10
+ }
11
+ export interface AuthProvidersConfig {
12
+ google?: GoogleOAuthConfig | boolean;
13
+ }
3
14
  export interface AuthLoginPluginOptions {
4
15
  enabled?: boolean;
5
16
  projectName?: string;
@@ -7,8 +18,15 @@ export interface AuthLoginPluginOptions {
7
18
  domain?: string;
8
19
  style?: AuthStyle;
9
20
  logo?: string;
10
- /** Enable Google OAuth — reads GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET from env */
11
- googleOAuth?: boolean;
21
+ /**
22
+ * OAuth providers configuration.
23
+ * - Omit entirely → auto-detect from env vars (GOOGLE_CLIENT_ID, etc.)
24
+ * - `{ google: true }` → use env vars
25
+ * - `{ google: { clientId, clientSecret } }` → use explicit values
26
+ * - `{ google: false }` → force-disable
27
+ * - `{ google: { enabled: false } }` → temporarily disable without losing config
28
+ */
29
+ providers?: AuthProvidersConfig;
12
30
  }
13
31
  export declare const authLoginPlugin: (options?: AuthLoginPluginOptions) => (config: Config) => Config;
14
32
  export { pluginConfig };
package/dist/index.js CHANGED
@@ -1,18 +1,59 @@
1
1
  import { authEndpoints } from './endpoints/authEndpoints.js';
2
2
  import { googleOAuthEndpoints } from './endpoints/googleOAuth.js';
3
3
  import { pluginConfig } from './config.js';
4
+ function resolveGoogleConfig(providers) {
5
+ const google = providers?.google;
6
+ // Explicitly disabled
7
+ if (google === false || typeof google === 'object' && google.enabled === false) {
8
+ return {
9
+ enabled: false,
10
+ clientId: '',
11
+ clientSecret: ''
12
+ };
13
+ }
14
+ // Explicit config provided
15
+ if (typeof google === 'object' && google.clientId && google.clientSecret) {
16
+ return {
17
+ enabled: true,
18
+ clientId: google.clientId,
19
+ clientSecret: google.clientSecret
20
+ };
21
+ }
22
+ // Auto-detect from env
23
+ const envId = process.env.GOOGLE_CLIENT_ID || '';
24
+ const envSecret = process.env.GOOGLE_CLIENT_SECRET || '';
25
+ const hasEnvCreds = !!(envId && envSecret);
26
+ return {
27
+ enabled: hasEnvCreds,
28
+ clientId: envId,
29
+ clientSecret: envSecret
30
+ };
31
+ }
32
+ /**
33
+ * Merge provider credentials into process.env so the OAuth endpoint can read them.
34
+ * This allows explicit plugin config values to work alongside env vars.
35
+ */ function setOAuthEnv(googleConfig) {
36
+ if (googleConfig.enabled && googleConfig.clientId) {
37
+ process.env.GOOGLE_CLIENT_ID = googleConfig.clientId;
38
+ process.env.GOOGLE_CLIENT_SECRET = googleConfig.clientSecret;
39
+ }
40
+ }
4
41
  export const authLoginPlugin = (options = {})=>(config)=>{
5
42
  if (options.enabled === false) return config;
6
- // Set global style config — all page components read this at render time
43
+ // Resolve provider config
44
+ const googleConfig = resolveGoogleConfig(options.providers);
45
+ setOAuthEnv(googleConfig);
46
+ // Set global config — all components read this at render time
7
47
  pluginConfig.style = options.style || 'tailwind';
8
48
  pluginConfig.logoUrl = options.logo;
49
+ pluginConfig.googleOAuthEnabled = googleConfig.enabled;
9
50
  // Register auth API endpoints
10
51
  config.endpoints = [
11
52
  ...config.endpoints || [],
12
53
  ...authEndpoints
13
54
  ];
14
- // Register Google OAuth endpoints if enabled
15
- if (options.googleOAuth !== false) {
55
+ // Register Google OAuth endpoints only if enabled
56
+ if (pluginConfig.googleOAuthEnabled) {
16
57
  config.endpoints = [
17
58
  ...config.endpoints,
18
59
  ...googleOAuthEndpoints
@@ -22,7 +63,7 @@ export const authLoginPlugin = (options = {})=>(config)=>{
22
63
  const incomingOnInit = config.onInit;
23
64
  config.onInit = async (payload)=>{
24
65
  if (incomingOnInit) await incomingOnInit(payload);
25
- payload.logger.info(`[auth-login] Initialized (style: ${pluginConfig.style}) for ${options.projectName || 'project'}`);
66
+ payload.logger.info(`[auth-login] Initialized (style: ${pluginConfig.style}, googleOAuth: ${pluginConfig.googleOAuthEnabled}) for ${options.projectName || 'project'}`);
26
67
  };
27
68
  return config;
28
69
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@main12/auth-login",
3
- "version": "0.1.7",
3
+ "version": "0.2.0",
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",