@main12/auth-login 0.1.8 → 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.
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. Default: auto-detects GOOGLE_CLIENT_ID env var. Set false to force-disable. */
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,52 @@
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;
43
+ // Resolve provider config
44
+ const googleConfig = resolveGoogleConfig(options.providers);
45
+ setOAuthEnv(googleConfig);
6
46
  // Set global config — all components read this at render time
7
47
  pluginConfig.style = options.style || 'tailwind';
8
48
  pluginConfig.logoUrl = options.logo;
9
- // Google OAuth: auto-detect from env vars
10
- if (options.googleOAuth === false) {
11
- pluginConfig.googleOAuthEnabled = false;
12
- } else {
13
- const hasGoogleCreds = !!(process.env.GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET);
14
- pluginConfig.googleOAuthEnabled = options.googleOAuth === true || hasGoogleCreds;
15
- }
49
+ pluginConfig.googleOAuthEnabled = googleConfig.enabled;
16
50
  // Register auth API endpoints
17
51
  config.endpoints = [
18
52
  ...config.endpoints || [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@main12/auth-login",
3
- "version": "0.1.8",
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",