@tidecloak/react 0.9.11

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/README.md ADDED
@@ -0,0 +1,230 @@
1
+ # TideCloak React SDK
2
+
3
+ Secure your React app with TideCloak: authentication, session management, and data encryption—all in minutes.
4
+
5
+ ---
6
+
7
+ ## 1. Prerequisites
8
+
9
+ Before you begin, ensure you have:
10
+
11
+ - React 18 or later
12
+ - Node.js >=18.17.0 or later
13
+ - A running TideCloak server.
14
+ - A registered client in your realm.
15
+
16
+ ---
17
+
18
+ ## 2. Install the SDK
19
+
20
+ Add the React package to your project:
21
+
22
+ ```bash
23
+ npm install @tidecloak/react
24
+ # or
25
+ yarn add @tidecloak/react
26
+ ```
27
+
28
+ This bundle provides:
29
+
30
+ - `<TideCloakProvider>` — application-level context.
31
+ - `useTideCloak()` hook — access tokens and auth actions.
32
+ - `<Authenticated>` / `<Unauthenticated>` — UI guards.
33
+
34
+ ---
35
+
36
+ ## 3. Initialize the Provider
37
+
38
+ Wrap your root component in `<TideCloakProvider>` to load adapter settings and bootstrap auth:
39
+
40
+ ```tsx
41
+ import React from 'react';
42
+ import { TideCloakProvider } from '@tidecloak/react';
43
+ import adapter from '../tidecloakAdapter.json';
44
+
45
+ export default function App() {
46
+ return (
47
+ <TideCloakProvider config={adapter}>
48
+ <YourApp />
49
+ </TideCloakProvider>
50
+ );
51
+ }
52
+ ```
53
+
54
+ **What it does:**
55
+
56
+ - **Loads** your adapter JSON.
57
+ - **Initializes** internal auth flows and listeners.
58
+ - **Provides** auth state & methods via React Context.
59
+
60
+ ---
61
+
62
+ ## 4. Using the `useTideCloak` Hook
63
+
64
+ Use this hook anywhere to manage auth:
65
+
66
+ ```tsx
67
+ import { useTideCloak } from '@tidecloak/react';
68
+
69
+ function Header() {
70
+ const {
71
+ authenticated,
72
+ login,
73
+ logout,
74
+ token,
75
+ tokenExp,
76
+ refreshToken,
77
+ getValueFromToken,
78
+ getValueFromIdToken,
79
+ hasRealmRole,
80
+ hasClientRole,
81
+ } = useTideCloak();
82
+
83
+ return (
84
+ <header>
85
+ {authenticated ? (
86
+ <>
87
+ <span>Logged in</span>
88
+ <button onClick={logout}>Log Out</button>
89
+ </>
90
+ ) : (
91
+ <button onClick={login}>Log In</button>
92
+ )}
93
+ {token && (
94
+ <small>Expires at {new Date(tokenExp * 1000).toLocaleTimeString()}</small>
95
+ )}
96
+ </header>
97
+ );
98
+ }
99
+ ```
100
+
101
+ **Key methods & props:**
102
+
103
+ | Name | Type | Description |
104
+ | ---------------------------------- | -------------------------------------------- | ----------------------------------------------------------------------- |
105
+ | `authenticated` | `boolean` | Whether the user is logged in. |
106
+ | `login()` / `logout()` | `() => void` | Trigger the login or logout flows. |
107
+ | `token`, `tokenExp` | `string`, `number` | Access token and its expiration timestamp. |
108
+ | Automatic token refresh | built-in | Tokens refresh silently on expiration—no manual setup needed. |
109
+ | `refreshToken()` | `() => Promise<boolean>` | Force a silent token renewal. |
110
+ | `getValueFromToken(key)` | `(key: string) => any` | Read a custom claim from the access token. |
111
+ | `getValueFromIdToken(key)` | `(key: string) => any` | Read a custom claim from the ID token. |
112
+ | `hasRealmRole(role)` | `(role: string) => boolean` | Check a realm-level role. |
113
+ | `hasClientRole(role, client?)` | `(role: string, client?: string) => boolean` | Check a client-level role; defaults to your app’s client ID if omitted. |
114
+ | `doEncrypt(data)``doDecrypt(data)` | `(data: any) => Promise<any>` | Encrypt or decrypt payloads via TideCloak’s built-in service. |
115
+
116
+ ---
117
+
118
+ ## 5. Guard Components
119
+
120
+ Use out-of-the-box components to show or hide content:
121
+
122
+ ```tsx
123
+ import { Authenticated, Unauthenticated } from '@tidecloak/react';
124
+
125
+ function Dashboard() {
126
+ return (
127
+ <>
128
+ <Authenticated>
129
+ <h1>Dashboard</h1>
130
+ {/* Protected widgets */}
131
+ </Authenticated>
132
+
133
+ <Unauthenticated>
134
+ <p>Please log in to access the dashboard.</p>
135
+ </Unauthenticated>
136
+ </>
137
+ );
138
+ }
139
+ ```
140
+
141
+ - `<Authenticated>`: renders children only when `authenticated === true`.
142
+ - `<Unauthenticated>`: renders children only when `authenticated === false`.
143
+
144
+ ---
145
+
146
+ ## 6. Encrypting & Decrypting Data
147
+
148
+ TideCloak lets you protect sensitive fields with **tag-based** encryption. You pass in an array of `{ data, tags }` objects and receive an array of encrypted strings (or vice versa for decryption).
149
+
150
+ ### Syntax Overview
151
+
152
+ ```ts
153
+ // Encrypt one or more payloads:
154
+ const encryptedArray: string[] = await doEncrypt([
155
+ { data: /* any JSON-serializable value */, tags: ['tag1', 'tag2'] },
156
+ // …
157
+ ]);
158
+
159
+ // Decrypt one or more encrypted blobs:
160
+ const decryptedArray: any[] = await doDecrypt([
161
+ { encrypted: /* string from encrypt() */, tags: ['tag1', 'tag2'] },
162
+ // …
163
+ ]);
164
+ ```
165
+
166
+ > **Order guarantee**: the returned array matches the input order.
167
+
168
+ ---
169
+
170
+ ### Encryption Example
171
+
172
+ ```tsx
173
+ import { useTideCloak } from '@tidecloak/react';
174
+
175
+ async function encryptExamples() {
176
+ const { doEncrypt } = useTideCloak();
177
+
178
+ // Simple single-item encryption:
179
+ const [encryptedDob] = await doEncrypt([
180
+ { data: '2005-03-04', tags: ['dob'] }
181
+ ]);
182
+
183
+ // Multi-field encryption:
184
+ const encryptedFields = await doEncrypt([
185
+ { data: '10 Smith Street', tags: ['street'] },
186
+ { data: 'Southport', tags: ['suburb'] },
187
+ { data: { full: '20 James Street – Burleigh Heads' }, tags: ['street', 'suburb'] }
188
+ ]);
189
+ }
190
+ ```
191
+
192
+ > **Permissions**: Users need roles matching **every** tag on a payload. A payload tagged `['street','suburb']` requires both the `tide_street.selfencrypt` and `tide_suburb.selfencrypt` roles.
193
+
194
+ ---
195
+
196
+ ### Decryption Example
197
+
198
+ ```tsx
199
+ import { useTideCloak } from '@tidecloak/react';
200
+
201
+ async function decryptExamples(encryptedFields: string[]) {
202
+ const { doDecrypt } = useTideCloak();
203
+
204
+ // Single-item decryption:
205
+ const [decryptedDob] = await doDecrypt([
206
+ { encrypted: encryptedFields[0], tags: ['dob'] }
207
+ ]);
208
+
209
+ // Multi-field decryption:
210
+ const decryptedFields = await doDecrypt([
211
+ { encrypted: encryptedFields[0], tags: ['street'] },
212
+ { encrypted: encryptedFields[1], tags: ['suburb'] },
213
+ { encrypted: encryptedFields[2], tags: ['street','suburb'] }
214
+ ]);
215
+ }
216
+ ```
217
+
218
+ > **Permissions**: Like encryption, decryption requires the same tag-based roles (`tide_street.selfdecrypt`, `tide_suburb.selfdecrypt`, etc.).
219
+
220
+ ---
221
+
222
+ ## 7. Advanced & Best Practices
223
+
224
+ - **Auto-Refresh**: built into the provider—no manual token timers needed.
225
+ - **Error Handling**: use the `initError` value from `useTideCloak` to catch startup issues.
226
+ - **Custom Claims**: store app-specific data in JWT claims and access via `getValueFromToken()` / `getValueFromIdToken()`.
227
+ - **Role-Based Access**: combine `hasRealmRole` and `hasClientRole` with guard components for fine-grained control.
228
+ - **Lazy Initialization**: wrap `<TideCloakProvider>` around only authenticated sections in large apps.
229
+
230
+ ---
@@ -0,0 +1,145 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React from "react";
3
+ import { IAMService } from '@tidecloak/js';
4
+ const TideCloakContext = React.createContext(undefined);
5
+ export function TideCloakContextProvider({ config, children }) {
6
+ const [isInitializing, setIsInitializing] = React.useState(true);
7
+ const [initError, setInitError] = React.useState(null);
8
+ const [authenticated, setAuthenticated] = React.useState(false);
9
+ const [sessionExpired, setSessionExpired] = React.useState(false);
10
+ const [isRefreshing, setIsRefreshing] = React.useState(false);
11
+ const [token, setToken] = React.useState(null);
12
+ const [idToken, setIdToken] = React.useState(null);
13
+ const [tokenExp, setTokenExp] = React.useState(null);
14
+ const [baseURL, setBaseURL] = React.useState("");
15
+ const [reloadKey, setReloadKey] = React.useState(0);
16
+ React.useEffect(() => {
17
+ let mounted = true;
18
+ const updateAuthState = async (eventName) => {
19
+ console.debug(`[TideCloak Provider] Updating auth state. Triggered by the ${eventName} event`);
20
+ if (!mounted)
21
+ return;
22
+ const logged = IAMService.isLoggedIn();
23
+ setAuthenticated(logged);
24
+ if (logged) {
25
+ setSessionExpired(false);
26
+ try {
27
+ const t = await IAMService.getToken();
28
+ const idt = IAMService.getIDToken();
29
+ setToken(t);
30
+ setIdToken(idt);
31
+ setTokenExp(IAMService.getTokenExp());
32
+ }
33
+ catch (e) {
34
+ console.error("[TideCloak Provider] Failed to update auth state", e);
35
+ }
36
+ }
37
+ else {
38
+ setSessionExpired(true);
39
+ setToken(null);
40
+ setIdToken(null);
41
+ }
42
+ };
43
+ const onInitError = (err) => {
44
+ if (mounted) {
45
+ setInitError(err);
46
+ setIsInitializing(false);
47
+ }
48
+ };
49
+ const onTokenExpired = async () => {
50
+ if (!mounted)
51
+ return;
52
+ console.debug("[TideCloak Provider] Token expired, attempting refresh...");
53
+ setSessionExpired(true);
54
+ try {
55
+ await IAMService.updateIAMToken();
56
+ }
57
+ catch (refreshError) {
58
+ console.error("[TideCloak Provider] Failed to refresh token:", refreshError);
59
+ }
60
+ };
61
+ IAMService
62
+ .on('authSuccess', updateAuthState)
63
+ .on('authError', updateAuthState)
64
+ .on('authRefreshSuccess', updateAuthState)
65
+ .on('authRefreshError', updateAuthState)
66
+ .on('logout', updateAuthState)
67
+ .on('tokenExpired', onTokenExpired)
68
+ .on('initError', onInitError);
69
+ setIsInitializing(true);
70
+ (async () => {
71
+ try {
72
+ const loaded = await IAMService.loadConfig(config);
73
+ ;
74
+ if (!loaded)
75
+ throw new Error("Invalid config");
76
+ setBaseURL(loaded['auth-server-url'].replace(/\/+$/, ''));
77
+ await IAMService.initIAM(config, updateAuthState);
78
+ if (!mounted)
79
+ return;
80
+ setIsInitializing(false);
81
+ }
82
+ catch (err) {
83
+ onInitError(err);
84
+ }
85
+ })();
86
+ return () => {
87
+ mounted = false;
88
+ IAMService.off('ready', updateAuthState)
89
+ .off('authSuccess', updateAuthState)
90
+ .off('authError', updateAuthState)
91
+ .off('authRefreshSuccess', updateAuthState)
92
+ .off('authRefreshError', updateAuthState)
93
+ .off('logout', updateAuthState)
94
+ .off('tokenExpired', onTokenExpired)
95
+ .off('initError', onInitError);
96
+ };
97
+ }, [config, reloadKey]);
98
+ if (isInitializing)
99
+ return null;
100
+ return (_jsx(TideCloakContext.Provider, { value: {
101
+ isInitializing,
102
+ initError,
103
+ authenticated,
104
+ sessionExpired,
105
+ isRefreshing,
106
+ token,
107
+ idToken,
108
+ tokenExp,
109
+ baseURL,
110
+ getConfig: () => IAMService.getConfig(),
111
+ reload: () => setReloadKey(k => k + 1),
112
+ login: () => IAMService.doLogin(),
113
+ logout: () => IAMService.doLogout(),
114
+ refreshToken: async () => {
115
+ setIsRefreshing(true);
116
+ try {
117
+ return await IAMService.updateIAMToken();
118
+ }
119
+ finally {
120
+ setIsRefreshing(false);
121
+ }
122
+ },
123
+ forceRefreshToken: async () => {
124
+ setIsRefreshing(true);
125
+ try {
126
+ return await IAMService.forceUpdateToken();
127
+ }
128
+ finally {
129
+ setIsRefreshing(false);
130
+ }
131
+ },
132
+ hasRealmRole: (role) => IAMService.hasRealmRole(role),
133
+ hasClientRole: (role, resource) => IAMService.hasClientRole(role, resource),
134
+ getValueFromToken: (key) => IAMService.getValueFromToken(key),
135
+ getValueFromIdToken: (key) => IAMService.getValueFromIDToken(key),
136
+ doEncrypt: async (data) => await IAMService.doEncrypt(data),
137
+ doDecrypt: async (data) => await IAMService.doDecrypt(data)
138
+ }, children: children }));
139
+ }
140
+ export function useTideCloakContext() {
141
+ const ctx = React.useContext(TideCloakContext);
142
+ if (!ctx)
143
+ throw new Error("useTideCloakContext must be used within <TideCloakContextProvider>");
144
+ return ctx;
145
+ }
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { TideCloakContextProvider, useTideCloakContext, } from './contexts/TideCloakContextProvider';
3
+ /**
4
+ * Wrap your app and bootstrap TideCloak with the given config object.
5
+ * tidecloak-js expects a plain JSON config, so we type config as Record<string, any>.
6
+ */
7
+ export const TideCloakProvider = ({ config, children }) => (_jsx(TideCloakContextProvider, { config: config, children: children }));
8
+ /**
9
+ * Hook to access authentication state and helpers.
10
+ */
11
+ export const useTideCloak = useTideCloakContext;
12
+ export function Authenticated({ children }) {
13
+ const { authenticated, isInitializing } = useTideCloakContext();
14
+ if (isInitializing)
15
+ return null;
16
+ return authenticated ? children : null;
17
+ }
18
+ export function Unauthenticated({ children }) {
19
+ const { authenticated, isInitializing } = useTideCloakContext();
20
+ if (isInitializing)
21
+ return null;
22
+ return !authenticated ? children : null;
23
+ }
@@ -0,0 +1,145 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React from "react";
3
+ import { IAMService } from '@tidecloak/js';
4
+ const TideCloakContext = React.createContext(undefined);
5
+ export function TideCloakContextProvider({ config, children }) {
6
+ const [isInitializing, setIsInitializing] = React.useState(true);
7
+ const [initError, setInitError] = React.useState(null);
8
+ const [authenticated, setAuthenticated] = React.useState(false);
9
+ const [sessionExpired, setSessionExpired] = React.useState(false);
10
+ const [isRefreshing, setIsRefreshing] = React.useState(false);
11
+ const [token, setToken] = React.useState(null);
12
+ const [idToken, setIdToken] = React.useState(null);
13
+ const [tokenExp, setTokenExp] = React.useState(null);
14
+ const [baseURL, setBaseURL] = React.useState("");
15
+ const [reloadKey, setReloadKey] = React.useState(0);
16
+ React.useEffect(() => {
17
+ let mounted = true;
18
+ const updateAuthState = async (eventName) => {
19
+ console.debug(`[TideCloak Provider] Updating auth state. Triggered by the ${eventName} event`);
20
+ if (!mounted)
21
+ return;
22
+ const logged = IAMService.isLoggedIn();
23
+ setAuthenticated(logged);
24
+ if (logged) {
25
+ setSessionExpired(false);
26
+ try {
27
+ const t = await IAMService.getToken();
28
+ const idt = IAMService.getIDToken();
29
+ setToken(t);
30
+ setIdToken(idt);
31
+ setTokenExp(IAMService.getTokenExp());
32
+ }
33
+ catch (e) {
34
+ console.error("[TideCloak Provider] Failed to update auth state", e);
35
+ }
36
+ }
37
+ else {
38
+ setSessionExpired(true);
39
+ setToken(null);
40
+ setIdToken(null);
41
+ }
42
+ };
43
+ const onInitError = (err) => {
44
+ if (mounted) {
45
+ setInitError(err);
46
+ setIsInitializing(false);
47
+ }
48
+ };
49
+ const onTokenExpired = async () => {
50
+ if (!mounted)
51
+ return;
52
+ console.debug("[TideCloak Provider] Token expired, attempting refresh...");
53
+ setSessionExpired(true);
54
+ try {
55
+ await IAMService.updateIAMToken();
56
+ }
57
+ catch (refreshError) {
58
+ console.error("[TideCloak Provider] Failed to refresh token:", refreshError);
59
+ }
60
+ };
61
+ IAMService
62
+ .on('authSuccess', updateAuthState)
63
+ .on('authError', updateAuthState)
64
+ .on('authRefreshSuccess', updateAuthState)
65
+ .on('authRefreshError', updateAuthState)
66
+ .on('logout', updateAuthState)
67
+ .on('tokenExpired', onTokenExpired)
68
+ .on('initError', onInitError);
69
+ setIsInitializing(true);
70
+ (async () => {
71
+ try {
72
+ const loaded = await IAMService.loadConfig(config);
73
+ ;
74
+ if (!loaded)
75
+ throw new Error("Invalid config");
76
+ setBaseURL(loaded['auth-server-url'].replace(/\/+$/, ''));
77
+ await IAMService.initIAM(config, updateAuthState);
78
+ if (!mounted)
79
+ return;
80
+ setIsInitializing(false);
81
+ }
82
+ catch (err) {
83
+ onInitError(err);
84
+ }
85
+ })();
86
+ return () => {
87
+ mounted = false;
88
+ IAMService.off('ready', updateAuthState)
89
+ .off('authSuccess', updateAuthState)
90
+ .off('authError', updateAuthState)
91
+ .off('authRefreshSuccess', updateAuthState)
92
+ .off('authRefreshError', updateAuthState)
93
+ .off('logout', updateAuthState)
94
+ .off('tokenExpired', onTokenExpired)
95
+ .off('initError', onInitError);
96
+ };
97
+ }, [config, reloadKey]);
98
+ if (isInitializing)
99
+ return null;
100
+ return (_jsx(TideCloakContext.Provider, { value: {
101
+ isInitializing,
102
+ initError,
103
+ authenticated,
104
+ sessionExpired,
105
+ isRefreshing,
106
+ token,
107
+ idToken,
108
+ tokenExp,
109
+ baseURL,
110
+ getConfig: () => IAMService.getConfig(),
111
+ reload: () => setReloadKey(k => k + 1),
112
+ login: () => IAMService.doLogin(),
113
+ logout: () => IAMService.doLogout(),
114
+ refreshToken: async () => {
115
+ setIsRefreshing(true);
116
+ try {
117
+ return await IAMService.updateIAMToken();
118
+ }
119
+ finally {
120
+ setIsRefreshing(false);
121
+ }
122
+ },
123
+ forceRefreshToken: async () => {
124
+ setIsRefreshing(true);
125
+ try {
126
+ return await IAMService.forceUpdateToken();
127
+ }
128
+ finally {
129
+ setIsRefreshing(false);
130
+ }
131
+ },
132
+ hasRealmRole: (role) => IAMService.hasRealmRole(role),
133
+ hasClientRole: (role, resource) => IAMService.hasClientRole(role, resource),
134
+ getValueFromToken: (key) => IAMService.getValueFromToken(key),
135
+ getValueFromIdToken: (key) => IAMService.getValueFromIDToken(key),
136
+ doEncrypt: async (data) => await IAMService.doEncrypt(data),
137
+ doDecrypt: async (data) => await IAMService.doDecrypt(data)
138
+ }, children: children }));
139
+ }
140
+ export function useTideCloakContext() {
141
+ const ctx = React.useContext(TideCloakContext);
142
+ if (!ctx)
143
+ throw new Error("useTideCloakContext must be used within <TideCloakContextProvider>");
144
+ return ctx;
145
+ }
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { TideCloakContextProvider, useTideCloakContext, } from './contexts/TideCloakContextProvider';
3
+ /**
4
+ * Wrap your app and bootstrap TideCloak with the given config object.
5
+ * tidecloak-js expects a plain JSON config, so we type config as Record<string, any>.
6
+ */
7
+ export const TideCloakProvider = ({ config, children }) => (_jsx(TideCloakContextProvider, { config: config, children: children }));
8
+ /**
9
+ * Hook to access authentication state and helpers.
10
+ */
11
+ export const useTideCloak = useTideCloakContext;
12
+ export function Authenticated({ children }) {
13
+ const { authenticated, isInitializing } = useTideCloakContext();
14
+ if (isInitializing)
15
+ return null;
16
+ return authenticated ? children : null;
17
+ }
18
+ export function Unauthenticated({ children }) {
19
+ const { authenticated, isInitializing } = useTideCloakContext();
20
+ if (isInitializing)
21
+ return null;
22
+ return !authenticated ? children : null;
23
+ }
@@ -0,0 +1,32 @@
1
+ import React from "react";
2
+ interface TideCloakContextValue {
3
+ isInitializing: boolean;
4
+ initError: Error | null;
5
+ authenticated: boolean;
6
+ sessionExpired: boolean;
7
+ isRefreshing: boolean;
8
+ token: string | null;
9
+ idToken: string | null;
10
+ tokenExp: number | null;
11
+ baseURL: string;
12
+ getConfig: () => Record<string, any>;
13
+ reload: () => void;
14
+ login: () => void;
15
+ logout: () => void;
16
+ refreshToken: () => Promise<boolean>;
17
+ forceRefreshToken: () => Promise<boolean>;
18
+ hasRealmRole: (role: string) => boolean;
19
+ hasClientRole: (role: string, resource?: string) => boolean;
20
+ getValueFromToken: (key: string) => any;
21
+ getValueFromIdToken: (key: string) => any;
22
+ doEncrypt: (data: any) => Promise<any>;
23
+ doDecrypt: (data: any) => Promise<any>;
24
+ }
25
+ interface TideCloakContextProviderProps {
26
+ config: Record<string, any>;
27
+ children: React.ReactNode;
28
+ }
29
+ export declare function TideCloakContextProvider({ config, children }: TideCloakContextProviderProps): import("react/jsx-runtime").JSX.Element | null;
30
+ export declare function useTideCloakContext(): TideCloakContextValue;
31
+ export {};
32
+ //# sourceMappingURL=TideCloakContextProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TideCloakContextProvider.d.ts","sourceRoot":"","sources":["../../../src/contexts/TideCloakContextProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,UAAU,qBAAqB;IAE7B,cAAc,EAAE,OAAO,CAAC;IACxB,SAAS,EAAE,KAAK,GAAG,IAAI,CAAC;IAGxB,aAAa,EAAE,OAAO,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,YAAY,EAAE,OAAO,CAAC;IAGtB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAGxB,OAAO,EAAE,MAAM,CAAC;IAGhB,SAAS,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACpC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,YAAY,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC,iBAAiB,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1C,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IACxC,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CAAA;IAC3D,iBAAiB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,GAAG,CAAC;IACxC,mBAAmB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,GAAG,CAAC;IAG1C,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IACtC,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;CACvC;AAED,UAAU,6BAA6B;IACrC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAID,wBAAgB,wBAAwB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,6BAA6B,kDA0I3F;AAED,wBAAgB,mBAAmB,IAAI,qBAAqB,CAI3D"}
@@ -0,0 +1,21 @@
1
+ import React, { ReactNode, FC } from 'react';
2
+ import { useTideCloakContext } from './contexts/TideCloakContextProvider';
3
+ /**
4
+ * Wrap your app and bootstrap TideCloak with the given config object.
5
+ * tidecloak-js expects a plain JSON config, so we type config as Record<string, any>.
6
+ */
7
+ export declare const TideCloakProvider: FC<{
8
+ config: Record<string, any>;
9
+ children: ReactNode;
10
+ }>;
11
+ /**
12
+ * Hook to access authentication state and helpers.
13
+ */
14
+ export declare const useTideCloak: typeof useTideCloakContext;
15
+ export declare function Authenticated({ children }: {
16
+ children: React.ReactNode;
17
+ }): React.ReactNode;
18
+ export declare function Unauthenticated({ children }: {
19
+ children: React.ReactNode;
20
+ }): React.ReactNode;
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAEL,mBAAmB,EACpB,MAAM,qCAAqC,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,EAAE,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAE,CAKpF,CAAC;AAEJ;;GAEG;AACH,eAAO,MAAM,YAAY,4BAAsB,CAAC;AAEhD,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,GAAG,KAAK,CAAC,SAAS,CAI1F;AAED,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,GAAG,KAAK,CAAC,SAAS,CAI5F"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@tidecloak/react",
3
+ "version": "0.9.11",
4
+ "description": "TideCloak client-side React SDK",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/types/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/esm/index.js",
11
+ "types": "./dist/types/index.d.ts",
12
+ "require": "./dist/cjs/src/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/tide-foundation/tidecloak-js.git"
24
+ },
25
+ "author": "Tide",
26
+ "license": "https://tide.org/licenses_tcoc2-0-0-en",
27
+ "keywords": [
28
+ "security",
29
+ "tidecloak",
30
+ "tide",
31
+ "authentication",
32
+ "oidc",
33
+ "oauth2",
34
+ "authorization",
35
+ "react"
36
+ ],
37
+ "peerDependencies": {
38
+ "react": ">=18.0.0"
39
+ },
40
+ "scripts": {
41
+ "build:cjs": "tsc -p tsconfig.cjs.json",
42
+ "build:esm": "tsc -p tsconfig.esm.json",
43
+ "build": "npm run build:cjs && npm run build:esm",
44
+ "prepare": "npm run build"
45
+ },
46
+ "devDependencies": {
47
+ "@types/react": "^19.1.8",
48
+ "@types/react-dom": "^19.1.6"
49
+ },
50
+ "dependencies": {
51
+ "@tidecloak/js": "^0.9.11"
52
+ }
53
+ }