@object-ui/auth 0.1.0 → 2.0.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.
@@ -9,6 +9,13 @@ import React from 'react';
9
9
  import type { AuthProviderConfig } from './types';
10
10
  export interface AuthProviderProps extends AuthProviderConfig {
11
11
  children: React.ReactNode;
12
+ /**
13
+ * Whether authentication is enabled.
14
+ * When false, the provider will skip authentication checks and treat all users as authenticated.
15
+ * Useful for development or demo environments where the server doesn't have authentication enabled.
16
+ * @default true
17
+ */
18
+ enabled?: boolean;
12
19
  }
13
20
  /**
14
21
  * Authentication context provider.
@@ -22,6 +29,13 @@ export interface AuthProviderProps extends AuthProviderConfig {
22
29
  * <App />
23
30
  * </AuthProvider>
24
31
  * ```
32
+ *
33
+ * @example With disabled auth (development mode)
34
+ * ```tsx
35
+ * <AuthProvider authUrl="/api/auth" enabled={false}>
36
+ * <App />
37
+ * </AuthProvider>
38
+ * ```
25
39
  */
26
- export declare function AuthProvider({ authUrl, client: externalClient, onAuthStateChange, children, }: AuthProviderProps): import("react/jsx-runtime").JSX.Element;
40
+ export declare function AuthProvider({ authUrl, client: externalClient, onAuthStateChange, enabled, children, }: AuthProviderProps): import("react/jsx-runtime").JSX.Element;
27
41
  //# sourceMappingURL=AuthProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../src/AuthProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAoD,MAAM,OAAO,CAAC;AACzE,OAAO,KAAK,EAAwB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAIxE,MAAM,WAAW,iBAAkB,SAAQ,kBAAkB;IAC3D,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,EAC3B,OAAO,EACP,MAAM,EAAE,cAAc,EACtB,iBAAiB,EACjB,QAAQ,GACT,EAAE,iBAAiB,2CAmKnB"}
1
+ {"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../src/AuthProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAoD,MAAM,OAAO,CAAC;AACzE,OAAO,KAAK,EAAwB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAIxE,MAAM,WAAW,iBAAkB,SAAQ,kBAAkB;IAC3D,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAAC,EAC3B,OAAO,EACP,MAAM,EAAE,cAAc,EACtB,iBAAiB,EACjB,OAAc,EACd,QAAQ,GACT,EAAE,iBAAiB,2CAqLnB"}
@@ -21,16 +21,40 @@ import { createAuthClient } from './createAuthClient';
21
21
  * <App />
22
22
  * </AuthProvider>
23
23
  * ```
24
+ *
25
+ * @example With disabled auth (development mode)
26
+ * ```tsx
27
+ * <AuthProvider authUrl="/api/auth" enabled={false}>
28
+ * <App />
29
+ * </AuthProvider>
30
+ * ```
24
31
  */
25
- export function AuthProvider({ authUrl, client: externalClient, onAuthStateChange, children, }) {
32
+ export function AuthProvider({ authUrl, client: externalClient, onAuthStateChange, enabled = true, children, }) {
26
33
  const client = useMemo(() => externalClient ?? createAuthClient({ baseURL: authUrl }), [externalClient, authUrl]);
27
34
  const [user, setUser] = useState(null);
28
35
  const [session, setSession] = useState(null);
29
36
  const [isLoading, setIsLoading] = useState(true);
30
37
  const [error, setError] = useState(null);
31
- const isAuthenticated = user !== null && session !== null;
32
- // Load session on mount
38
+ // If auth is disabled, automatically set as authenticated with a guest user
39
+ const isAuthenticated = enabled
40
+ ? user !== null && session !== null
41
+ : true;
42
+ // Load session on mount (only if auth is enabled)
33
43
  useEffect(() => {
44
+ if (!enabled) {
45
+ // When auth is disabled, set a guest user and mark as loaded
46
+ setUser({
47
+ id: 'guest',
48
+ email: 'guest@local',
49
+ name: 'Guest User',
50
+ });
51
+ setSession({
52
+ token: 'guest-token',
53
+ expiresAt: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000), // 1 year
54
+ });
55
+ setIsLoading(false);
56
+ return;
57
+ }
34
58
  let cancelled = false;
35
59
  async function loadSession() {
36
60
  try {
@@ -55,7 +79,7 @@ export function AuthProvider({ authUrl, client: externalClient, onAuthStateChang
55
79
  }
56
80
  loadSession();
57
81
  return () => { cancelled = true; };
58
- }, [client]);
82
+ }, [client, enabled]);
59
83
  // Notify on auth state changes
60
84
  useEffect(() => {
61
85
  onAuthStateChange?.({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/auth",
3
- "version": "0.1.0",
3
+ "version": "2.0.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Authentication system for Object UI with AuthProvider, useAuth hook, AuthGuard, and form components.",
@@ -26,7 +26,7 @@
26
26
  "react": "^18.0.0 || ^19.0.0"
27
27
  },
28
28
  "dependencies": {
29
- "@object-ui/types": "0.5.0"
29
+ "@object-ui/types": "2.0.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/react": "^19.2.13",