@tidecloak/react 0.13.9 → 0.13.13

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.
@@ -0,0 +1,161 @@
1
+ import { useState, useEffect, useCallback, useRef } from 'react';
2
+ import { IAMService } from '@tidecloak/js';
3
+ /**
4
+ * Parse OAuth callback data from URL and sessionStorage.
5
+ */
6
+ function parseCallback() {
7
+ const params = new URLSearchParams(window.location.search);
8
+ const code = params.get('code');
9
+ const state = params.get('state') || '';
10
+ const error = params.get('error');
11
+ const errorDescription = params.get('error_description');
12
+ const isCallback = !!(code || error);
13
+ // Parse state parameter (format: verifier__url_returnUrl or just returnUrl)
14
+ let verifier = sessionStorage.getItem('kc_pkce_verifier');
15
+ let returnUrl = sessionStorage.getItem('kc_return_url');
16
+ // Also try to extract return URL from state if it contains __url_
17
+ if (state && state.includes('__url_')) {
18
+ const urlStart = state.indexOf('__url_') + 6;
19
+ returnUrl = state.substring(urlStart) || returnUrl;
20
+ }
21
+ return {
22
+ code,
23
+ state,
24
+ verifier,
25
+ returnUrl,
26
+ error,
27
+ errorDescription,
28
+ isCallback,
29
+ };
30
+ }
31
+ /**
32
+ * Hook for handling OAuth callback pages in hybrid mode.
33
+ *
34
+ * Automatically detects if the current page is an OAuth callback and processes it.
35
+ *
36
+ * @example
37
+ * ```tsx
38
+ * function OAuthCallback() {
39
+ * const { isProcessing, isSuccess, error, returnUrl } = useAuthCallback({
40
+ * onSuccess: (url) => navigate(url || '/'),
41
+ * onError: (err) => console.error(err),
42
+ * });
43
+ *
44
+ * if (isProcessing) return <Spinner />;
45
+ * if (error) return <ErrorMessage error={error} />;
46
+ * return null;
47
+ * }
48
+ * ```
49
+ */
50
+ export function useAuthCallback(options = {}) {
51
+ const { autoProcess = true, onSuccess, onError, onMissingVerifierRedirectTo, } = options;
52
+ const [state, setState] = useState(() => {
53
+ const parsed = parseCallback();
54
+ return {
55
+ isCallback: parsed.isCallback,
56
+ isProcessing: false,
57
+ isSuccess: false,
58
+ error: null,
59
+ returnUrl: parsed.returnUrl,
60
+ code: parsed.code,
61
+ idpError: parsed.error,
62
+ idpErrorDescription: parsed.errorDescription,
63
+ };
64
+ });
65
+ // Track if we've already processed to prevent double-execution in StrictMode
66
+ const processedRef = useRef(false);
67
+ const onSuccessRef = useRef(onSuccess);
68
+ const onErrorRef = useRef(onError);
69
+ // Keep refs updated
70
+ useEffect(() => {
71
+ onSuccessRef.current = onSuccess;
72
+ onErrorRef.current = onError;
73
+ }, [onSuccess, onError]);
74
+ const processCallback = useCallback(async () => {
75
+ var _a, _b, _c, _d, _e, _f;
76
+ // Guard against double processing
77
+ if (processedRef.current)
78
+ return;
79
+ processedRef.current = true;
80
+ setState(s => ({ ...s, isProcessing: true }));
81
+ try {
82
+ const parsed = parseCallback();
83
+ // Check for IdP error first
84
+ if (parsed.error) {
85
+ const error = new Error(parsed.errorDescription || parsed.error);
86
+ setState(s => ({
87
+ ...s,
88
+ isProcessing: false,
89
+ error,
90
+ idpError: parsed.error,
91
+ idpErrorDescription: parsed.errorDescription,
92
+ }));
93
+ (_a = onErrorRef.current) === null || _a === void 0 ? void 0 : _a.call(onErrorRef, error);
94
+ return;
95
+ }
96
+ if (!parsed.code) {
97
+ setState(s => ({ ...s, isProcessing: false }));
98
+ return;
99
+ }
100
+ // Check for missing verifier (page was refreshed)
101
+ if (!parsed.verifier) {
102
+ if (onMissingVerifierRedirectTo) {
103
+ window.location.assign(onMissingVerifierRedirectTo);
104
+ return;
105
+ }
106
+ const error = new Error('Session expired. Please try logging in again.');
107
+ setState(s => ({ ...s, isProcessing: false, error }));
108
+ (_b = onErrorRef.current) === null || _b === void 0 ? void 0 : _b.call(onErrorRef, error);
109
+ return;
110
+ }
111
+ // Get config and let IAMService handle the callback
112
+ const config = IAMService.getConfig();
113
+ if (!config) {
114
+ const error = new Error('IAMService not configured. Call loadConfig() first.');
115
+ setState(s => ({ ...s, isProcessing: false, error }));
116
+ (_c = onErrorRef.current) === null || _c === void 0 ? void 0 : _c.call(onErrorRef, error);
117
+ return;
118
+ }
119
+ // Initialize IAMService which will handle the token exchange
120
+ const authenticated = await IAMService.initIAM(config);
121
+ if (authenticated) {
122
+ // Try to get return URL from sessionStorage since we can't access internal state
123
+ const returnUrl = sessionStorage.getItem('kc_return_url') || parsed.returnUrl;
124
+ setState(s => ({
125
+ ...s,
126
+ isProcessing: false,
127
+ isSuccess: true,
128
+ returnUrl,
129
+ }));
130
+ (_d = onSuccessRef.current) === null || _d === void 0 ? void 0 : _d.call(onSuccessRef, returnUrl);
131
+ }
132
+ else {
133
+ const error = new Error('Authentication failed');
134
+ setState(s => ({ ...s, isProcessing: false, error }));
135
+ (_e = onErrorRef.current) === null || _e === void 0 ? void 0 : _e.call(onErrorRef, error);
136
+ }
137
+ }
138
+ catch (err) {
139
+ const error = err instanceof Error ? err : new Error(String(err));
140
+ setState(s => ({ ...s, isProcessing: false, error }));
141
+ (_f = onErrorRef.current) === null || _f === void 0 ? void 0 : _f.call(onErrorRef, error);
142
+ }
143
+ }, [onMissingVerifierRedirectTo]);
144
+ // Auto-process on mount if enabled and this is a callback
145
+ useEffect(() => {
146
+ if (autoProcess && state.isCallback && !processedRef.current) {
147
+ processCallback();
148
+ }
149
+ }, [autoProcess, state.isCallback, processCallback]);
150
+ return {
151
+ ...state,
152
+ processCallback,
153
+ };
154
+ }
155
+ /**
156
+ * Parse OAuth callback data from URL without using IAMService.
157
+ * Useful for manual token exchange flows.
158
+ */
159
+ export function parseCallbackUrl() {
160
+ return parseCallback();
161
+ }
package/dist/esm/index.js CHANGED
@@ -1,19 +1,98 @@
1
- import { useTideCloakContext, } from './contexts/TideCloakContextProvider';
1
+ import React from 'react';
2
+ import { useTideCloakContext } from './contexts/TideCloakContextProvider';
2
3
  export { TideCloakContextProvider } from './contexts/TideCloakContextProvider';
3
- export { RequestEnclave } from "@tidecloak/js";
4
+ // Hybrid mode utilities
5
+ export { useAuthCallback, parseCallbackUrl } from './hooks/useAuthCallback';
6
+ export { AuthCallback, SimpleAuthCallback } from './components/AuthCallback';
7
+ export { RequestEnclave, AdminAPI } from "@tidecloak/js";
4
8
  /**
5
9
  * Hook to access authentication state and helpers.
10
+ * Must be used within a TideCloakContextProvider.
6
11
  */
7
12
  export const useTideCloak = useTideCloakContext;
13
+ /**
14
+ * Renders children only when user is authenticated.
15
+ */
8
16
  export function Authenticated({ children }) {
9
17
  const { authenticated, isInitializing } = useTideCloakContext();
10
18
  if (isInitializing)
11
19
  return null;
12
20
  return authenticated ? children : null;
13
21
  }
22
+ /**
23
+ * Renders children only when user is NOT authenticated.
24
+ */
14
25
  export function Unauthenticated({ children }) {
15
26
  const { authenticated, isInitializing } = useTideCloakContext();
16
27
  if (isInitializing)
17
28
  return null;
18
29
  return !authenticated ? children : null;
19
30
  }
31
+ /**
32
+ * Renders children only when user has the specified realm role.
33
+ */
34
+ export function HasRealmRole({ role, children, fallback = null }) {
35
+ const { authenticated, isInitializing, hasRealmRole } = useTideCloakContext();
36
+ if (isInitializing)
37
+ return null;
38
+ if (!authenticated)
39
+ return fallback;
40
+ return hasRealmRole(role) ? children : fallback;
41
+ }
42
+ /**
43
+ * Renders children only when user has the specified client/resource role.
44
+ */
45
+ export function HasClientRole({ role, resource, children, fallback = null }) {
46
+ const { authenticated, isInitializing, hasClientRole } = useTideCloakContext();
47
+ if (isInitializing)
48
+ return null;
49
+ if (!authenticated)
50
+ return fallback;
51
+ return hasClientRole(role, resource) ? children : fallback;
52
+ }
53
+ /**
54
+ * Renders children only when user is offline.
55
+ */
56
+ export function Offline({ children }) {
57
+ const { isOffline } = useTideCloakContext();
58
+ return isOffline ? children : null;
59
+ }
60
+ /**
61
+ * Renders children only when user is online.
62
+ */
63
+ export function Online({ children }) {
64
+ const { isOffline } = useTideCloakContext();
65
+ return !isOffline ? children : null;
66
+ }
67
+ /**
68
+ * Renders children when the user was offline at some point during the session.
69
+ * Useful for showing "sync needed" banners.
70
+ */
71
+ export function WasOffline({ children, onReset }) {
72
+ const { wasOffline, resetWasOffline } = useTideCloakContext();
73
+ const handleReset = React.useCallback(() => {
74
+ resetWasOffline();
75
+ onReset === null || onReset === void 0 ? void 0 : onReset();
76
+ }, [resetWasOffline, onReset]);
77
+ if (!wasOffline)
78
+ return null;
79
+ // If children is a function, pass the reset handler
80
+ if (typeof children === 'function') {
81
+ return children(handleReset);
82
+ }
83
+ return children;
84
+ }
85
+ /**
86
+ * Renders children when re-authentication is needed (e.g., after 401).
87
+ */
88
+ export function NeedsReauth({ children }) {
89
+ const { needsReauth } = useTideCloakContext();
90
+ return needsReauth ? children : null;
91
+ }
92
+ /**
93
+ * Renders loading state during login/logout operations.
94
+ */
95
+ export function AuthLoading({ children }) {
96
+ const { isLoading } = useTideCloakContext();
97
+ return isLoading ? children : null;
98
+ }
@@ -0,0 +1,90 @@
1
+ import React from 'react';
2
+ import { UseAuthCallbackOptions } from '../hooks/useAuthCallback';
3
+ export interface AuthCallbackProps extends UseAuthCallbackOptions {
4
+ /**
5
+ * Component to render while processing the callback.
6
+ * @default null
7
+ */
8
+ loadingComponent?: React.ReactNode;
9
+ /**
10
+ * Component to render when authentication fails.
11
+ * Receives the error as a prop.
12
+ */
13
+ errorComponent?: React.ComponentType<{
14
+ error: Error;
15
+ }> | React.ReactNode;
16
+ /**
17
+ * Component to render when authentication succeeds.
18
+ * Receives the returnUrl as a prop.
19
+ */
20
+ successComponent?: React.ComponentType<{
21
+ returnUrl: string | null;
22
+ }> | React.ReactNode;
23
+ /**
24
+ * Children to render when this is not a callback page.
25
+ */
26
+ children?: React.ReactNode;
27
+ }
28
+ /**
29
+ * Component for handling OAuth callback pages in hybrid mode.
30
+ *
31
+ * Drop this component into your callback route and it handles everything:
32
+ * - Detecting if this is a callback page
33
+ * - Processing the authorization code
34
+ * - Exchanging tokens with your backend
35
+ * - Calling onSuccess/onError callbacks
36
+ *
37
+ * @example
38
+ * ```tsx
39
+ * // Simple usage with navigation
40
+ * function OAuthCallbackPage() {
41
+ * const navigate = useNavigate();
42
+ *
43
+ * return (
44
+ * <AuthCallback
45
+ * onSuccess={(returnUrl) => navigate(returnUrl || '/')}
46
+ * onError={(error) => console.error(error)}
47
+ * loadingComponent={<Spinner />}
48
+ * errorComponent={({ error }) => <Alert status="error">{error.message}</Alert>}
49
+ * />
50
+ * );
51
+ * }
52
+ *
53
+ * // Or in routes directly
54
+ * <Route path="/auth/callback" element={
55
+ * <AuthCallback
56
+ * onSuccess={(url) => window.location.assign(url || '/')}
57
+ * loadingComponent={<LoadingScreen />}
58
+ * />
59
+ * } />
60
+ * ```
61
+ */
62
+ export declare function AuthCallback({ loadingComponent, errorComponent, successComponent, children, ...options }: AuthCallbackProps): React.ReactNode;
63
+ /**
64
+ * Simple callback page that auto-redirects on success.
65
+ * Use this when you just want the callback handled with minimal UI.
66
+ *
67
+ * @example
68
+ * ```tsx
69
+ * <Route path="/auth/callback" element={
70
+ * <SimpleAuthCallback
71
+ * defaultRedirect="/"
72
+ * loginPage="/login"
73
+ * loadingComponent={<FullPageSpinner />}
74
+ * />
75
+ * } />
76
+ * ```
77
+ */
78
+ export declare function SimpleAuthCallback({ defaultRedirect, loginPage, loadingComponent, errorComponent, }: {
79
+ /** URL to redirect to if no returnUrl is available */
80
+ defaultRedirect?: string;
81
+ /** URL to redirect to if verifier is missing (page refreshed) */
82
+ loginPage?: string;
83
+ /** Component to show while processing */
84
+ loadingComponent?: React.ReactNode;
85
+ /** Component to show on error */
86
+ errorComponent?: React.ComponentType<{
87
+ error: Error;
88
+ }> | React.ReactNode;
89
+ }): React.ReactNode;
90
+ //# sourceMappingURL=AuthCallback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthCallback.d.ts","sourceRoot":"","sources":["../../../src/components/AuthCallback.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAmB,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAEnF,MAAM,WAAW,iBAAkB,SAAQ,sBAAsB;IAC/D;;;OAGG;IACH,gBAAgB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAEnC;;;OAGG;IACH,cAAc,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC;IAEzE;;;OAGG;IACH,gBAAgB,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;QAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC;IAEvF;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,YAAY,CAAC,EAC3B,gBAAuB,EACvB,cAAc,EACd,gBAAgB,EAChB,QAAQ,EACR,GAAG,OAAO,EACX,EAAE,iBAAiB,GAAG,KAAK,CAAC,SAAS,CAsCrC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,eAAqB,EACrB,SAAoB,EACpB,gBAAgB,EAChB,cAAc,GACf,EAAE;IACD,sDAAsD;IACtD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,gBAAgB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACnC,iCAAiC;IACjC,cAAc,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC;CAC1E,GAAG,KAAK,CAAC,SAAS,CAWlB"}
@@ -1,32 +1,118 @@
1
1
  import React from "react";
2
- interface TideCloakContextValue {
2
+ import { IAMService, NativeAdapter, AdminAPI } from '@tidecloak/js';
3
+ type AuthSuccessCallback = () => void | Promise<void>;
4
+ type AuthErrorCallback = (error: Error) => void;
5
+ type LogoutCallback = () => void;
6
+ type ReauthCallback = () => void;
7
+ export type ActionNotificationType = 'success' | 'error' | 'info' | 'warning';
8
+ export interface ActionNotification {
9
+ type: ActionNotificationType;
10
+ title: string;
11
+ message?: string;
12
+ action?: string;
13
+ }
14
+ type ActionNotificationCallback = (notification: ActionNotification) => void;
15
+ export interface TideCloakContextValue {
3
16
  isInitializing: boolean;
4
17
  initError: Error | null;
5
18
  authenticated: boolean;
6
19
  sessionExpired: boolean;
7
20
  isRefreshing: boolean;
21
+ isLoading: boolean;
22
+ isOffline: boolean;
23
+ wasOffline: boolean;
24
+ needsReauth: boolean;
8
25
  token: string | null;
9
26
  idToken: string | null;
10
27
  tokenExp: number | null;
11
28
  baseURL: string;
29
+ IAMService: typeof IAMService;
30
+ AdminAPI: typeof AdminAPI;
12
31
  getConfig: () => Record<string, any>;
13
32
  reload: () => void;
14
- login: () => void;
15
- logout: () => void;
33
+ login: () => Promise<void>;
34
+ logout: () => Promise<void>;
35
+ getToken: () => Promise<string | null>;
16
36
  refreshToken: () => Promise<boolean>;
17
37
  forceRefreshToken: () => Promise<boolean>;
18
38
  hasRealmRole: (role: string) => boolean;
19
39
  hasClientRole: (role: string, resource?: string) => boolean;
20
40
  getValueFromToken: (key: string) => any;
21
41
  getValueFromIdToken: (key: string) => any;
42
+ triggerReauth: () => void;
43
+ clearReauth: () => void;
44
+ resetWasOffline: () => void;
22
45
  doEncrypt: (data: any) => Promise<any>;
23
46
  doDecrypt: (data: any) => Promise<any>;
47
+ initializeTideRequest: <T extends {
48
+ encode: () => Uint8Array;
49
+ }>(request: T) => Promise<T>;
50
+ getVendorId: () => string;
51
+ getResource: () => string;
52
+ approveTideRequests: (requests: {
53
+ id: string;
54
+ request: Uint8Array;
55
+ }[]) => Promise<{
56
+ id: string;
57
+ approved?: {
58
+ request: Uint8Array;
59
+ };
60
+ denied?: boolean;
61
+ pending?: boolean;
62
+ }[]>;
24
63
  }
25
- interface TideCloakContextProviderProps {
26
- config: Record<string, any>;
64
+ export interface TideCloakContextProviderProps {
27
65
  children: React.ReactNode;
66
+ /**
67
+ * Full TideCloak configuration. If not provided, will be fetched from configUrl.
68
+ */
69
+ config?: Record<string, any>;
70
+ /**
71
+ * URL to fetch adapter.json from. Defaults to '/adapter.json'.
72
+ * Only used if config prop is not provided.
73
+ */
74
+ configUrl?: string;
75
+ /**
76
+ * Authentication mode. Must be explicitly specified.
77
+ * - 'native': For Electron/Tauri/React Native apps (requires adapter prop)
78
+ * - undefined: Standard frontchannel mode (browser-based)
79
+ */
80
+ authMode?: 'native';
81
+ /**
82
+ * Native adapter for Electron/Tauri/React Native apps.
83
+ * Required when authMode is 'native'.
84
+ *
85
+ * @example
86
+ * ```tsx
87
+ * <TideCloakContextProvider
88
+ * authMode="native"
89
+ * adapter={createElectronAdapter()}
90
+ * >
91
+ * <App />
92
+ * </TideCloakContextProvider>
93
+ * ```
94
+ */
95
+ adapter?: NativeAdapter;
96
+ onAuthSuccess?: AuthSuccessCallback;
97
+ onAuthError?: AuthErrorCallback;
98
+ onLogout?: LogoutCallback;
99
+ onReauthRequired?: ReauthCallback;
100
+ /**
101
+ * Callback for action notifications (approvals, encryption, etc.)
102
+ * Use this to integrate with your own notification system (toast, snackbar, etc.)
103
+ *
104
+ * @example
105
+ * ```tsx
106
+ * <TideCloakContextProvider
107
+ * onActionNotification={({ type, title, message }) => {
108
+ * toast[type](message || title);
109
+ * }}
110
+ * >
111
+ * ```
112
+ */
113
+ onActionNotification?: ActionNotificationCallback;
28
114
  }
29
- export declare function TideCloakContextProvider({ config, children }: TideCloakContextProviderProps): import("react/jsx-runtime").JSX.Element | null;
115
+ export declare function TideCloakContextProvider({ config: configProp, configUrl, authMode, adapter, children, onAuthSuccess, onAuthError, onLogout, onReauthRequired, onActionNotification }: TideCloakContextProviderProps): import("react/jsx-runtime").JSX.Element;
30
116
  export declare function useTideCloakContext(): TideCloakContextValue;
31
117
  export {};
32
118
  //# sourceMappingURL=TideCloakContextProvider.d.ts.map
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,WAAW,EACX,QAAQ,EACR,gBAAgB,EAChB,oBAAoB,EACrB,EAAE,6BAA6B,2CAmlB/B;AA0CD,wBAAgB,mBAAmB,IAAI,qBAAqB,CAS3D"}
@@ -0,0 +1,80 @@
1
+ export interface AuthCallbackState {
2
+ /** Whether this is a callback page (has code or error in URL) */
3
+ isCallback: boolean;
4
+ /** Whether callback processing is in progress */
5
+ isProcessing: boolean;
6
+ /** Whether authentication completed successfully */
7
+ isSuccess: boolean;
8
+ /** Error that occurred during authentication */
9
+ error: Error | null;
10
+ /** URL to return to after authentication */
11
+ returnUrl: string | null;
12
+ /** Authorization code from IdP (if available) */
13
+ code: string | null;
14
+ /** Error code from IdP (if auth was denied) */
15
+ idpError: string | null;
16
+ /** Error description from IdP */
17
+ idpErrorDescription: string | null;
18
+ }
19
+ export interface UseAuthCallbackOptions {
20
+ /**
21
+ * Whether to automatically process the callback.
22
+ * Set to false for manual control.
23
+ * @default true
24
+ */
25
+ autoProcess?: boolean;
26
+ /**
27
+ * Called when authentication succeeds.
28
+ * Typically used to navigate to returnUrl.
29
+ */
30
+ onSuccess?: (returnUrl: string | null) => void;
31
+ /**
32
+ * Called when authentication fails.
33
+ */
34
+ onError?: (error: Error) => void;
35
+ /**
36
+ * Override the redirect URI (useful when config isn't loaded yet).
37
+ */
38
+ redirectUri?: string;
39
+ /**
40
+ * URL to redirect to if PKCE verifier is missing (e.g., page refresh).
41
+ * Typically the login page.
42
+ */
43
+ onMissingVerifierRedirectTo?: string;
44
+ }
45
+ /**
46
+ * Hook for handling OAuth callback pages in hybrid mode.
47
+ *
48
+ * Automatically detects if the current page is an OAuth callback and processes it.
49
+ *
50
+ * @example
51
+ * ```tsx
52
+ * function OAuthCallback() {
53
+ * const { isProcessing, isSuccess, error, returnUrl } = useAuthCallback({
54
+ * onSuccess: (url) => navigate(url || '/'),
55
+ * onError: (err) => console.error(err),
56
+ * });
57
+ *
58
+ * if (isProcessing) return <Spinner />;
59
+ * if (error) return <ErrorMessage error={error} />;
60
+ * return null;
61
+ * }
62
+ * ```
63
+ */
64
+ export declare function useAuthCallback(options?: UseAuthCallbackOptions): AuthCallbackState & {
65
+ /** Manually trigger callback processing */
66
+ processCallback: () => Promise<void>;
67
+ };
68
+ /**
69
+ * Parse OAuth callback data from URL without using IAMService.
70
+ * Useful for manual token exchange flows.
71
+ */
72
+ export declare function parseCallbackUrl(): {
73
+ code: string | null;
74
+ state: string | null;
75
+ verifier: string | null;
76
+ returnUrl: string | null;
77
+ error: string | null;
78
+ errorDescription: string | null;
79
+ };
80
+ //# sourceMappingURL=useAuthCallback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuthCallback.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAuthCallback.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,iBAAiB;IAChC,iEAAiE;IACjE,UAAU,EAAE,OAAO,CAAC;IACpB,iDAAiD;IACjD,YAAY,EAAE,OAAO,CAAC;IACtB,oDAAoD;IACpD,SAAS,EAAE,OAAO,CAAC;IACnB,gDAAgD;IAChD,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,4CAA4C;IAC5C,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,iDAAiD;IACjD,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,iCAAiC;IACjC,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC;AAED,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAE/C;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAEjC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,2BAA2B,CAAC,EAAE,MAAM,CAAC;CACtC;AA2CD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,iBAAiB,GAAG;IACzF,2CAA2C;IAC3C,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC,CAyHA;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI;IAClC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC,CAEA"}
@@ -1,15 +1,77 @@
1
1
  import React from 'react';
2
2
  import { useTideCloakContext } from './contexts/TideCloakContextProvider';
3
3
  export { TideCloakContextProvider } from './contexts/TideCloakContextProvider';
4
- export { RequestEnclave } from "@tidecloak/js";
4
+ export type { TideCloakContextValue, TideCloakContextProviderProps, ActionNotification, ActionNotificationType } from './contexts/TideCloakContextProvider';
5
+ export type { NativeAdapter, NativeTokenData, NativeAuthCallbackResult } from "@tidecloak/js";
6
+ export { useAuthCallback, parseCallbackUrl } from './hooks/useAuthCallback';
7
+ export type { AuthCallbackState, UseAuthCallbackOptions } from './hooks/useAuthCallback';
8
+ export { AuthCallback, SimpleAuthCallback } from './components/AuthCallback';
9
+ export type { AuthCallbackProps } from './components/AuthCallback';
10
+ export { RequestEnclave, AdminAPI } from "@tidecloak/js";
5
11
  /**
6
12
  * Hook to access authentication state and helpers.
13
+ * Must be used within a TideCloakContextProvider.
7
14
  */
8
15
  export declare const useTideCloak: typeof useTideCloakContext;
16
+ /**
17
+ * Renders children only when user is authenticated.
18
+ */
9
19
  export declare function Authenticated({ children }: {
10
20
  children: React.ReactNode;
11
21
  }): React.ReactNode;
22
+ /**
23
+ * Renders children only when user is NOT authenticated.
24
+ */
12
25
  export declare function Unauthenticated({ children }: {
13
26
  children: React.ReactNode;
14
27
  }): React.ReactNode;
28
+ /**
29
+ * Renders children only when user has the specified realm role.
30
+ */
31
+ export declare function HasRealmRole({ role, children, fallback }: {
32
+ role: string;
33
+ children: React.ReactNode;
34
+ fallback?: React.ReactNode;
35
+ }): React.ReactNode;
36
+ /**
37
+ * Renders children only when user has the specified client/resource role.
38
+ */
39
+ export declare function HasClientRole({ role, resource, children, fallback }: {
40
+ role: string;
41
+ resource?: string;
42
+ children: React.ReactNode;
43
+ fallback?: React.ReactNode;
44
+ }): React.ReactNode;
45
+ /**
46
+ * Renders children only when user is offline.
47
+ */
48
+ export declare function Offline({ children }: {
49
+ children: React.ReactNode;
50
+ }): React.ReactNode;
51
+ /**
52
+ * Renders children only when user is online.
53
+ */
54
+ export declare function Online({ children }: {
55
+ children: React.ReactNode;
56
+ }): React.ReactNode;
57
+ /**
58
+ * Renders children when the user was offline at some point during the session.
59
+ * Useful for showing "sync needed" banners.
60
+ */
61
+ export declare function WasOffline({ children, onReset }: {
62
+ children: React.ReactNode;
63
+ onReset?: () => void;
64
+ }): React.ReactNode;
65
+ /**
66
+ * Renders children when re-authentication is needed (e.g., after 401).
67
+ */
68
+ export declare function NeedsReauth({ children }: {
69
+ children: React.ReactNode;
70
+ }): React.ReactNode;
71
+ /**
72
+ * Renders loading state during login/logout operations.
73
+ */
74
+ export declare function AuthLoading({ children }: {
75
+ children: React.ReactNode;
76
+ }): React.ReactNode;
15
77
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAC7C,OAAO,EACL,mBAAmB,EACpB,MAAM,qCAAqC,CAAC;AAE7C,OAAQ,EAAE,wBAAwB,EAAE,MAAM,q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