@fastshot/auth 1.0.4 → 1.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastshot/auth",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "OAuth authentication SDK for Expo React Native applications with Supabase",
5
5
  "main": "src/index.ts",
6
6
  "repository": {
package/src/auth.ts CHANGED
@@ -4,7 +4,6 @@
4
4
 
5
5
  import * as WebBrowser from 'expo-web-browser';
6
6
  import type { SupabaseClient, Session } from '@supabase/supabase-js';
7
- import { AUTH_CONFIG } from './constants';
8
7
  import type {
9
8
  OAuthProvider,
10
9
  AuthMode,
@@ -20,22 +19,7 @@ import {
20
19
  restoreSession,
21
20
  createAuthError,
22
21
  } from './utils';
23
-
24
- /**
25
- * Get the project ID from environment variables
26
- */
27
- function getProjectId(): string {
28
- const projectId = AUTH_CONFIG.PROJECT_ID;
29
-
30
- if (!projectId) {
31
- throw createAuthError(
32
- 'UNKNOWN_ERROR',
33
- 'Project ID not found. Ensure EXPO_PUBLIC_PROJECT_ID is set in your .env file.'
34
- );
35
- }
36
-
37
- return projectId;
38
- }
22
+ import { getProjectId } from './env';
39
23
 
40
24
  /**
41
25
  * Configuration for sign-in function
package/src/constants.ts CHANGED
@@ -1,31 +1,19 @@
1
- /**
2
- * Get environment variable with fallback
3
- * Works in both React Native (process.env.EXPO_PUBLIC_*) and Node.js environments
4
- */
5
- function getEnvVar(key: string, fallback: string): string {
6
- // React Native / Expo environment
7
- if (typeof process !== 'undefined' && process.env) {
8
- return process.env[key] || fallback;
9
- }
10
- return fallback;
11
- }
1
+ import { ENV } from './env';
12
2
 
13
3
  /**
14
4
  * Auth Broker configuration
15
- * URLs are read from environment variables at runtime
16
5
  *
17
- * Required env vars:
18
- * - EXPO_PUBLIC_AUTH_BROKER_URL: Auth broker service URL
19
- * - EXPO_PUBLIC_PROJECT_ID: Fastshot project ID
6
+ * Environment values are resolved from process.env.EXPO_PUBLIC_*
7
+ * which are inlined by babel at build time.
20
8
  */
21
9
  export const AUTH_CONFIG = {
22
- /** Auth broker URL - must be set via EXPO_PUBLIC_AUTH_BROKER_URL */
10
+ /** Auth broker URL */
23
11
  get AUTH_BROKER_URL(): string {
24
- return getEnvVar('EXPO_PUBLIC_AUTH_BROKER_URL', '');
12
+ return ENV.AUTH_BROKER_URL;
25
13
  },
26
14
  /** Project ID for authentication */
27
- get PROJECT_ID(): string | undefined {
28
- return getEnvVar('EXPO_PUBLIC_PROJECT_ID', '');
15
+ get PROJECT_ID(): string {
16
+ return ENV.PROJECT_ID;
29
17
  },
30
18
  /** Deep link scheme for OAuth callback */
31
19
  DEEP_LINK_SCHEME: 'fastshot',
package/src/env.ts ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Environment configuration for @fastshot/auth
3
+ *
4
+ * Uses direct process.env access which is inlined by babel at build time.
5
+ * The babel.config.js in the template includes an override for @fastshot/*
6
+ * packages that uses transform-inline-environment-variables plugin.
7
+ *
8
+ * If env vars are not properly inlined, these functions will throw errors
9
+ * to help developers identify configuration issues.
10
+ */
11
+
12
+ /**
13
+ * Check if a value looks like an uninlined env var reference
14
+ * This happens when babel doesn't inline the value
15
+ */
16
+ function isUninlined(value: string | undefined): value is undefined | '' {
17
+ return !value || value === 'undefined' || value.startsWith('process.env.');
18
+ }
19
+
20
+ /**
21
+ * Get the Fastshot Project ID
22
+ * @throws Error if EXPO_PUBLIC_PROJECT_ID is not configured
23
+ */
24
+ export function getProjectId(): string {
25
+ const value = process.env.EXPO_PUBLIC_PROJECT_ID;
26
+
27
+ if (isUninlined(value)) {
28
+ throw new Error(
29
+ '[@fastshot/auth] EXPO_PUBLIC_PROJECT_ID is not configured.\n\n' +
30
+ 'Make sure:\n' +
31
+ '1. EXPO_PUBLIC_PROJECT_ID is set in your .env file\n' +
32
+ '2. babel.config.js has the @fastshot/* override with transform-inline-environment-variables\n' +
33
+ '3. You\'ve cleared Metro cache after changing .env (npx expo start --clear)\n'
34
+ );
35
+ }
36
+
37
+ return value as string;
38
+ }
39
+
40
+ /**
41
+ * Get the Auth Broker URL
42
+ * warns if EXPO_PUBLIC_AUTH_BROKER_URL is not configured
43
+ */
44
+ export function getAuthBrokerUrl(): string {
45
+ const value = process.env.EXPO_PUBLIC_AUTH_BROKER_URL;
46
+
47
+ if (isUninlined(value)) {
48
+ console.warn(
49
+ '[@fastshot/auth] EXPO_PUBLIC_AUTH_BROKER_URL is not configured.\n\n' +
50
+ 'Make sure:\n' +
51
+ '1. EXPO_PUBLIC_AUTH_BROKER_URL is set in your .env file\n' +
52
+ '2. babel.config.js has the @fastshot/* override with transform-inline-environment-variables\n' +
53
+ '3. You\'ve cleared Metro cache after changing .env (npx expo start --clear)\n'
54
+ );
55
+ return 'https://oauth.fastshot.ai';
56
+ }
57
+
58
+ return value as string;
59
+ }
60
+
61
+ /**
62
+ * Environment configuration object with lazy evaluation
63
+ * Values are resolved on first access and will throw if not configured
64
+ */
65
+ export const ENV = {
66
+ get PROJECT_ID(): string {
67
+ return getProjectId();
68
+ },
69
+ get AUTH_BROKER_URL(): string {
70
+ return getAuthBrokerUrl();
71
+ },
72
+ } as const;
package/src/index.ts CHANGED
@@ -98,3 +98,6 @@ export type {
98
98
 
99
99
  // Constants (for debugging/customization)
100
100
  export { AUTH_CONFIG, AUTH_ENDPOINTS } from './constants';
101
+
102
+ // Environment utilities
103
+ export { getProjectId, getAuthBrokerUrl, ENV } from './env';