@workos-inc/authkit-nextjs 0.17.2 → 1.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.
- package/README.md +102 -25
- package/dist/esm/actions.js +11 -0
- package/dist/esm/actions.js.map +1 -1
- package/dist/esm/components/authkit-provider.js +128 -0
- package/dist/esm/components/authkit-provider.js.map +1 -0
- package/dist/esm/components/button.js.map +1 -0
- package/dist/esm/{impersonation.js → components/impersonation.js} +12 -7
- package/dist/esm/components/impersonation.js.map +1 -0
- package/dist/esm/components/index.js +4 -0
- package/dist/esm/components/index.js.map +1 -0
- package/dist/esm/components/min-max-button.js.map +1 -0
- package/dist/esm/env-variables.js +5 -2
- package/dist/esm/env-variables.js.map +1 -1
- package/dist/esm/index.js +4 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/middleware.js +5 -2
- package/dist/esm/middleware.js.map +1 -1
- package/dist/esm/session.js +104 -107
- package/dist/esm/session.js.map +1 -1
- package/dist/esm/types/actions.d.ts +6 -0
- package/dist/esm/types/components/authkit-provider.d.ts +33 -0
- package/dist/esm/types/{impersonation.d.ts → components/impersonation.d.ts} +1 -1
- package/dist/esm/types/components/index.d.ts +3 -0
- package/dist/esm/types/env-variables.d.ts +2 -2
- package/dist/esm/types/index.d.ts +3 -5
- package/dist/esm/types/interfaces.d.ts +11 -0
- package/dist/esm/types/middleware.d.ts +3 -2
- package/dist/esm/types/session.d.ts +5 -28
- package/dist/esm/types/workos.d.ts +1 -1
- package/dist/esm/workos.js +1 -1
- package/dist/esm/workos.js.map +1 -1
- package/package.json +11 -1
- package/src/actions.ts +20 -0
- package/src/components/authkit-provider.tsx +169 -0
- package/src/{impersonation.tsx → components/impersonation.tsx} +14 -7
- package/src/components/index.ts +4 -0
- package/src/env-variables.ts +7 -2
- package/src/index.ts +3 -8
- package/src/interfaces.ts +13 -0
- package/src/middleware.ts +8 -4
- package/src/session.ts +137 -124
- package/src/workos.ts +1 -1
- package/dist/esm/authkit-provider.js +0 -52
- package/dist/esm/authkit-provider.js.map +0 -1
- package/dist/esm/button.js.map +0 -1
- package/dist/esm/impersonation.js.map +0 -1
- package/dist/esm/min-max-button.js.map +0 -1
- package/dist/esm/types/authkit-provider.d.ts +0 -11
- package/src/authkit-provider.tsx +0 -66
- /package/dist/esm/{button.js → components/button.js} +0 -0
- /package/dist/esm/{min-max-button.js → components/min-max-button.js} +0 -0
- /package/dist/esm/types/{button.d.ts → components/button.d.ts} +0 -0
- /package/dist/esm/types/{min-max-button.d.ts → components/min-max-button.d.ts} +0 -0
- /package/src/{button.tsx → components/button.tsx} +0 -0
- /package/src/{min-max-button.tsx → components/min-max-button.tsx} +0 -0
package/README.md
CHANGED
|
@@ -143,10 +143,10 @@ Custom redirect URIs will be used over a redirect URI configured in the environm
|
|
|
143
143
|
|
|
144
144
|
### Wrap your app in `AuthKitProvider`
|
|
145
145
|
|
|
146
|
-
Use `AuthKitProvider` to wrap your app layout, which adds
|
|
146
|
+
Use `AuthKitProvider` to wrap your app layout, which provides client side auth methods adds protections for auth edge cases.
|
|
147
147
|
|
|
148
148
|
```jsx
|
|
149
|
-
import { AuthKitProvider } from '@workos-inc/authkit-nextjs';
|
|
149
|
+
import { AuthKitProvider } from '@workos-inc/authkit-nextjs/components';
|
|
150
150
|
|
|
151
151
|
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
152
152
|
return (
|
|
@@ -159,9 +159,9 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
159
159
|
}
|
|
160
160
|
```
|
|
161
161
|
|
|
162
|
-
### Get the current user
|
|
162
|
+
### Get the current user in a server component
|
|
163
163
|
|
|
164
|
-
For pages where you want to display a signed-in and signed-out view, use `withAuth` to retrieve the user
|
|
164
|
+
For pages where you want to display a signed-in and signed-out view, use `withAuth` to retrieve the user session from WorkOS.
|
|
165
165
|
|
|
166
166
|
```jsx
|
|
167
167
|
import Link from 'next/link';
|
|
@@ -200,16 +200,84 @@ export default async function HomePage() {
|
|
|
200
200
|
}
|
|
201
201
|
```
|
|
202
202
|
|
|
203
|
+
### Get the current user in a client component
|
|
204
|
+
|
|
205
|
+
For client components, use the `useAuth` hook to get the current user session.
|
|
206
|
+
|
|
207
|
+
```jsx
|
|
208
|
+
// Note the updated import path
|
|
209
|
+
import { useAuth } from '@workos-inc/authkit-nextjs/components';
|
|
210
|
+
|
|
211
|
+
export default function MyComponent() {
|
|
212
|
+
// Retrieves the user from the session or returns `null` if no user is signed in
|
|
213
|
+
const { user, loading } = useAuth();
|
|
214
|
+
|
|
215
|
+
if (loading) {
|
|
216
|
+
return <div>Loading...</div>;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return <div>{user?.firstName}</div>;
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
203
223
|
### Requiring auth
|
|
204
224
|
|
|
205
225
|
For pages where a signed-in user is mandatory, you can use the `ensureSignedIn` option:
|
|
206
226
|
|
|
207
227
|
```jsx
|
|
228
|
+
// Server component
|
|
208
229
|
const { user } = await withAuth({ ensureSignedIn: true });
|
|
230
|
+
|
|
231
|
+
// Client component
|
|
232
|
+
const { user, loading } = useAuth({ ensureSignedIn: true });
|
|
209
233
|
```
|
|
210
234
|
|
|
211
235
|
Enabling `ensureSignedIn` will redirect users to AuthKit if they attempt to access the page without being authenticated.
|
|
212
236
|
|
|
237
|
+
### Refreshing the session
|
|
238
|
+
|
|
239
|
+
Use the `refreshSession` method in a server action or route handler to fetch the latest session details, including any changes to the user's roles or permissions.
|
|
240
|
+
|
|
241
|
+
The `organizationId` parameter can be passed to `refreshSession` in order to switch the session to a different organization. If the current session is not authorized for the next organization, an appropriate [authentication error](https://workos.com/docs/reference/user-management/authentication-errors) will be returned.
|
|
242
|
+
|
|
243
|
+
In client components, you can refresh the session with the `refreshAuth` hook.
|
|
244
|
+
|
|
245
|
+
```tsx
|
|
246
|
+
'use client';
|
|
247
|
+
|
|
248
|
+
import { useAuth } from '@workos-inc/authkit-nextjs/components';
|
|
249
|
+
import React, { useEffect } from 'react';
|
|
250
|
+
|
|
251
|
+
export function SwitchOrganizationButton() {
|
|
252
|
+
const { user, organizationId, loading, refreshAuth } = useAuth();
|
|
253
|
+
|
|
254
|
+
useEffect(() => {
|
|
255
|
+
// This will log out the new organizationId after refreshing the session
|
|
256
|
+
console.log('organizationId', organizationId);
|
|
257
|
+
}, [organizationId]);
|
|
258
|
+
|
|
259
|
+
if (loading) {
|
|
260
|
+
return <div>Loading...</div>;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const handleRefreshSession = async () => {
|
|
264
|
+
const result = await refreshAuth({
|
|
265
|
+
// Provide the organizationId to switch to
|
|
266
|
+
organizationId: 'org_123',
|
|
267
|
+
});
|
|
268
|
+
if (result?.error) {
|
|
269
|
+
console.log('Error refreshing session:', result.error);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
if (user) {
|
|
274
|
+
return <button onClick={handleRefreshSession}>Refresh session</button>;
|
|
275
|
+
} else {
|
|
276
|
+
return <div>Not signed in</div>;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
213
281
|
### Middleware auth
|
|
214
282
|
|
|
215
283
|
The default behavior of this library is to request authentication via the `withAuth` method on a per-page basis. There are some use cases where you don't want to call `withAuth` (e.g. you don't need user data for your page) or if you'd prefer a "secure by default" approach where every route defined in your middleware matcher is protected unless specified otherwise. In those cases you can opt-in to use middleware auth instead:
|
|
@@ -233,27 +301,36 @@ In the above example the `/admin` page will require a user to be signed in, wher
|
|
|
233
301
|
|
|
234
302
|
`unauthenticatedPaths` uses the same glob logic as the [Next.js matcher](https://nextjs.org/docs/pages/building-your-application/routing/middleware#matcher).
|
|
235
303
|
|
|
236
|
-
###
|
|
304
|
+
### Composing middleware
|
|
237
305
|
|
|
238
|
-
|
|
306
|
+
If you don't want to use `authkitMiddleware` and instead want to compose your own middleware, you can use the `authkit` method. In this mode you are responsible to handling what to do when there's no session on a protected route.
|
|
239
307
|
|
|
240
308
|
```ts
|
|
241
|
-
|
|
242
|
-
|
|
309
|
+
export default async function middleware(request: NextRequest) {
|
|
310
|
+
// Perform logic before or after AuthKit
|
|
243
311
|
|
|
244
|
-
|
|
245
|
-
//
|
|
246
|
-
const
|
|
312
|
+
// Auth object contains the session, response headers and an auhorization URL in the case that the session isn't valid
|
|
313
|
+
// This method will automatically handle setting the cookie and refreshing the session
|
|
314
|
+
const { session, headers, authorizationUrl } = await authkit(request, {
|
|
315
|
+
debug: true,
|
|
316
|
+
});
|
|
247
317
|
|
|
248
|
-
//
|
|
249
|
-
|
|
318
|
+
// Control of what to do when there's no session on a protected route is left to the developer
|
|
319
|
+
if (request.url.includes('/account') && !session.user) {
|
|
320
|
+
console.log('No session on protected path');
|
|
321
|
+
return NextResponse.redirect(authorizationUrl);
|
|
250
322
|
|
|
251
|
-
|
|
323
|
+
// Alternatively you could redirect to your own login page, for example if you want to use your own UI instead of hosted AuthKit
|
|
324
|
+
return NextResponse.redirect('/login');
|
|
325
|
+
}
|
|
252
326
|
|
|
253
|
-
|
|
327
|
+
// Headers from the authkit response need to be included in every non-redirect response to ensure that `withAuth` works as expected
|
|
328
|
+
return NextResponse.next({
|
|
329
|
+
headers: headers,
|
|
330
|
+
});
|
|
254
331
|
}
|
|
255
332
|
|
|
256
|
-
// Match against pages
|
|
333
|
+
// Match against the pages
|
|
257
334
|
export const config = { matcher: ['/', '/account/:path*'] };
|
|
258
335
|
```
|
|
259
336
|
|
|
@@ -267,13 +344,15 @@ Render the `Impersonation` component in your app so that it is clear when someon
|
|
|
267
344
|
The component will display a frame with some information about the impersonated user, as well as a button to stop impersonating.
|
|
268
345
|
|
|
269
346
|
```jsx
|
|
270
|
-
import { Impersonation } from '@workos-inc/authkit-nextjs';
|
|
347
|
+
import { Impersonation, AuthKitProvider } from '@workos-inc/authkit-nextjs/components';
|
|
271
348
|
|
|
272
349
|
export default function App() {
|
|
273
350
|
return (
|
|
274
351
|
<div>
|
|
275
|
-
<
|
|
276
|
-
|
|
352
|
+
<AuthKitProvider>
|
|
353
|
+
<Impersonation />
|
|
354
|
+
{/* Your app content */}
|
|
355
|
+
</AuthKitProvider>
|
|
277
356
|
</div>
|
|
278
357
|
);
|
|
279
358
|
}
|
|
@@ -303,12 +382,6 @@ export default async function HomePage() {
|
|
|
303
382
|
}
|
|
304
383
|
```
|
|
305
384
|
|
|
306
|
-
### Refreshing the session
|
|
307
|
-
|
|
308
|
-
Use the `refreshSession` method in a server action or route handler to fetch the latest session details, including any changes to the user's roles or permissions.
|
|
309
|
-
|
|
310
|
-
The `organizationId` parameter can be passed to `refreshSession` in order to switch the session to a different organization. If the current session is not authorized for the next organization, an appropriate [authentication error](https://workos.com/docs/reference/user-management/authentication-errors) will be returned.
|
|
311
|
-
|
|
312
385
|
### Sign up paths
|
|
313
386
|
|
|
314
387
|
The `signUpPaths` option can be passed to `authkitMiddleware` to specify paths that should use the 'sign-up' screen hint when redirecting to AuthKit. This is useful for cases where you want a path that mandates authentication to be treated as a sign up page.
|
|
@@ -336,3 +409,7 @@ export default authkitMiddleware({ debug: true });
|
|
|
336
409
|
#### NEXT_REDIRECT error when using try/catch blocks
|
|
337
410
|
|
|
338
411
|
Wrapping a `withAuth({ ensureSignedIn: true })` call in a try/catch block will cause a `NEXT_REDIRECT` error. This is because `withAuth` will attempt to redirect the user to AuthKit if no session is detected and redirects in Next must be [called outside a try/catch](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#redirecting).
|
|
412
|
+
|
|
413
|
+
#### Module build failed: UnhandledSchemeError: Reading from "node:crypto" is not handled by plugins (Unhandled scheme).
|
|
414
|
+
|
|
415
|
+
You may encounter this error if you attempt to import server side code from authkit-nextjs into a client component. Likely you are using `withAuth` in a client component instead of the `useAuth` hook. Either move the code to a server component or use the `useAuth` hook.
|
package/dist/esm/actions.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
import { signOut } from './auth.js';
|
|
3
|
+
import { refreshSession, withAuth } from './session.js';
|
|
4
|
+
import { workos } from './workos.js';
|
|
3
5
|
/**
|
|
4
6
|
* This action is only accessible to authenticated users,
|
|
5
7
|
* there is no need to check the session here as the middleware will
|
|
@@ -11,4 +13,13 @@ export const checkSessionAction = async () => {
|
|
|
11
13
|
export const handleSignOutAction = async () => {
|
|
12
14
|
await signOut();
|
|
13
15
|
};
|
|
16
|
+
export const getOrganizationAction = async (organizationId) => {
|
|
17
|
+
return await workos.organizations.getOrganization(organizationId);
|
|
18
|
+
};
|
|
19
|
+
export const getAuthAction = async (ensureSignedIn) => {
|
|
20
|
+
return await withAuth({ ensureSignedIn: ensureSignedIn });
|
|
21
|
+
};
|
|
22
|
+
export const refreshAuthAction = async ({ ensureSignedIn, organizationId, }) => {
|
|
23
|
+
return await refreshSession({ ensureSignedIn, organizationId });
|
|
24
|
+
};
|
|
14
25
|
//# sourceMappingURL=actions.js.map
|
package/dist/esm/actions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/actions.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/actions.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,IAAI,EAAE;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,IAAI,EAAE;IAC5C,MAAM,OAAO,EAAE,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EAAE,cAAsB,EAAE,EAAE;IACpE,OAAO,MAAM,MAAM,CAAC,aAAa,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;AACpE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,cAAwB,EAAE,EAAE;IAC9D,OAAO,MAAM,QAAQ,CAAC,EAAE,cAAc,EAAE,cAAuB,EAAE,CAAC,CAAC;AACrE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,EACtC,cAAc,EACd,cAAc,GAIf,EAAE,EAAE;IACH,OAAO,MAAM,cAAc,CAAC,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC,CAAC;AAClE,CAAC,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
3
|
+
import { checkSessionAction, getAuthAction, refreshAuthAction } from '../actions.js';
|
|
4
|
+
const AuthContext = createContext(undefined);
|
|
5
|
+
export const AuthKitProvider = ({ children, onSessionExpired }) => {
|
|
6
|
+
const [user, setUser] = useState(null);
|
|
7
|
+
const [sessionId, setSessionId] = useState(undefined);
|
|
8
|
+
const [organizationId, setOrganizationId] = useState(undefined);
|
|
9
|
+
const [role, setRole] = useState(undefined);
|
|
10
|
+
const [permissions, setPermissions] = useState(undefined);
|
|
11
|
+
const [entitlements, setEntitlements] = useState(undefined);
|
|
12
|
+
const [impersonator, setImpersonator] = useState(undefined);
|
|
13
|
+
const [accessToken, setAccessToken] = useState(undefined);
|
|
14
|
+
const [loading, setLoading] = useState(true);
|
|
15
|
+
const getAuth = async ({ ensureSignedIn = false } = {}) => {
|
|
16
|
+
try {
|
|
17
|
+
const auth = await getAuthAction(ensureSignedIn);
|
|
18
|
+
setUser(auth.user);
|
|
19
|
+
setSessionId(auth.sessionId);
|
|
20
|
+
setOrganizationId(auth.organizationId);
|
|
21
|
+
setRole(auth.role);
|
|
22
|
+
setPermissions(auth.permissions);
|
|
23
|
+
setEntitlements(auth.entitlements);
|
|
24
|
+
setImpersonator(auth.impersonator);
|
|
25
|
+
setAccessToken(auth.accessToken);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
setUser(null);
|
|
29
|
+
setSessionId(undefined);
|
|
30
|
+
setOrganizationId(undefined);
|
|
31
|
+
setRole(undefined);
|
|
32
|
+
setPermissions(undefined);
|
|
33
|
+
setEntitlements(undefined);
|
|
34
|
+
setImpersonator(undefined);
|
|
35
|
+
setAccessToken(undefined);
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
setLoading(false);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const refreshAuth = async ({ ensureSignedIn = false, organizationId, } = {}) => {
|
|
42
|
+
try {
|
|
43
|
+
setLoading(true);
|
|
44
|
+
const auth = await refreshAuthAction({ ensureSignedIn, organizationId });
|
|
45
|
+
setUser(auth.user);
|
|
46
|
+
setSessionId(auth.sessionId);
|
|
47
|
+
setOrganizationId(auth.organizationId);
|
|
48
|
+
setRole(auth.role);
|
|
49
|
+
setPermissions(auth.permissions);
|
|
50
|
+
setEntitlements(auth.entitlements);
|
|
51
|
+
setImpersonator(auth.impersonator);
|
|
52
|
+
setAccessToken(auth.accessToken);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
return error instanceof Error ? { error: error.message } : { error: String(error) };
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
setLoading(false);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
getAuth();
|
|
63
|
+
// Return early if the session expired checks are disabled.
|
|
64
|
+
if (onSessionExpired === false) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
let visibilityChangedCalled = false;
|
|
68
|
+
const handleVisibilityChange = async () => {
|
|
69
|
+
if (visibilityChangedCalled) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// In the case where we're using middleware auth mode, a user that has signed out in a different tab
|
|
73
|
+
// will run into an issue if they attempt to hit a server action in the original tab.
|
|
74
|
+
// This will force a refresh of the page in that case, which will redirect them to the sign-in page.
|
|
75
|
+
if (document.visibilityState === 'visible') {
|
|
76
|
+
visibilityChangedCalled = true;
|
|
77
|
+
try {
|
|
78
|
+
const hasSession = await checkSessionAction();
|
|
79
|
+
if (!hasSession) {
|
|
80
|
+
throw new Error('Session expired');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
// 'Failed to fetch' is the error we are looking for if the action fails
|
|
85
|
+
// If any other error happens, for other reasons, we should not reload the page
|
|
86
|
+
if (error instanceof Error && error.message.includes('Failed to fetch')) {
|
|
87
|
+
if (onSessionExpired) {
|
|
88
|
+
onSessionExpired();
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
window.location.reload();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
visibilityChangedCalled = false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
window.addEventListener('visibilitychange', handleVisibilityChange);
|
|
101
|
+
window.addEventListener('focus', handleVisibilityChange);
|
|
102
|
+
return () => {
|
|
103
|
+
window.removeEventListener('focus', handleVisibilityChange);
|
|
104
|
+
window.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
105
|
+
};
|
|
106
|
+
}, [onSessionExpired]);
|
|
107
|
+
return (React.createElement(AuthContext.Provider, { value: {
|
|
108
|
+
user,
|
|
109
|
+
sessionId,
|
|
110
|
+
organizationId,
|
|
111
|
+
role,
|
|
112
|
+
permissions,
|
|
113
|
+
entitlements,
|
|
114
|
+
impersonator,
|
|
115
|
+
accessToken,
|
|
116
|
+
loading,
|
|
117
|
+
getAuth,
|
|
118
|
+
refreshAuth,
|
|
119
|
+
} }, children));
|
|
120
|
+
};
|
|
121
|
+
export function useAuth() {
|
|
122
|
+
const context = useContext(AuthContext);
|
|
123
|
+
if (!context) {
|
|
124
|
+
throw new Error('useAuth must be used within an AuthKitProvider');
|
|
125
|
+
}
|
|
126
|
+
return context;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=authkit-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authkit-provider.js","sourceRoot":"","sources":["../../../src/components/authkit-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,EAAE,EAAE,aAAa,EAAa,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAiBrF,MAAM,WAAW,GAAG,aAAa,CAA8B,SAAS,CAAC,CAAC;AAW1E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAAE,QAAQ,EAAE,gBAAgB,EAAwB,EAAE,EAAE;IACtF,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAc,IAAI,CAAC,CAAC;IACpD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAqB,SAAS,CAAC,CAAC;IAC1E,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAqB,SAAS,CAAC,CAAC;IACpF,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAqB,SAAS,CAAC,CAAC;IAChE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAuB,SAAS,CAAC,CAAC;IAChF,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAuB,SAAS,CAAC,CAAC;IAClF,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAA2B,SAAS,CAAC,CAAC;IACt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OAAO;IACrB,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IACxC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button.js","sourceRoot":"","sources":["../../../src/components/button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,CAA8D,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE;IACnH,OAAO,CACL,gCACE,GAAG,EAAE,YAAY,EACjB,IAAI,EAAC,QAAQ,KACT,KAAK,EACT,KAAK,EAAE;YACL,OAAO,EAAE,aAAa;YACtB,UAAU,EAAE,QAAQ;YACpB,cAAc,EAAE,QAAQ;YACxB,UAAU,EAAE,CAAC;YACb,MAAM,EAAE,SAAS;YACjB,OAAO,EAAE,SAAS;YAElB,UAAU,EAAE,SAAS;YACrB,QAAQ,EAAE,SAAS;YACnB,YAAY,EAAE,6CAA6C;YAC3D,MAAM,EAAE,MAAM;YACd,eAAe,EAAE,aAAa;YAC9B,KAAK,EAAE,OAAO;YAEd,GAAG,KAAK,CAAC,KAAK;SACf,GACD,CACH,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAC;AAE9B,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import * as React from 'react';
|
|
2
|
-
import { withAuth } from './session.js';
|
|
3
|
-
import { workos } from './workos.js';
|
|
4
3
|
import { Button } from './button.js';
|
|
5
4
|
import { MinMaxButton } from './min-max-button.js';
|
|
6
|
-
import { handleSignOutAction } from '
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import { getOrganizationAction, handleSignOutAction } from '../actions.js';
|
|
6
|
+
import { useAuth } from './authkit-provider.js';
|
|
7
|
+
export function Impersonation({ side = 'bottom', ...props }) {
|
|
8
|
+
const { user, impersonator, organizationId, loading } = useAuth();
|
|
9
|
+
const [organization, setOrganization] = React.useState(null);
|
|
10
|
+
React.useEffect(() => {
|
|
11
|
+
if (!organizationId)
|
|
12
|
+
return;
|
|
13
|
+
getOrganizationAction(organizationId).then(setOrganization);
|
|
14
|
+
}, [organizationId]);
|
|
15
|
+
if (loading || !impersonator || !user)
|
|
10
16
|
return null;
|
|
11
|
-
const organization = organizationId ? await workos.organizations.getOrganization(organizationId) : null;
|
|
12
17
|
return (React.createElement("div", { ...props, "data-workos-impersonation-root": "", style: {
|
|
13
18
|
'position': 'fixed',
|
|
14
19
|
'inset': 0,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"impersonation.js","sourceRoot":"","sources":["../../../src/components/impersonation.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAMhD,MAAM,UAAU,aAAa,CAAC,EAAE,IAAI,GAAG,QAAQ,EAAE,GAAG,KAAK,EAAsB;IAC7E,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;IAElE,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAsB,IAAI,CAAC,CAAC;IAElF,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,CAAC,cAAc;YAA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AAE,UAAU,EAAE,uBAAuB,EAAE,WAAW,EAAE,aAAa,EAAE,WAEvF;gBACT,oBAAC,YAAY,IAAC,cAAc,EAAC,GAAG,IAAE,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAgB,CACvE;YAEP,6BACE,KAAK,EAAE;oBACL,OAAO,EAAE,aAAa;oBAEtB,QAAQ,EAAE,OAAO;oBACjB,KAAK,EAAE,aAAa;oBAEpB,aAAa,EAAE,MAAM;oBACrB,eAAe,EAAE,eAAe;oBAChC,MAAM,EAAE,iCAAiC;oBACzC,YAAY,EAAE,aAAa;oBAE3B,UAAU,EAAE,yCAAyC;oBACrD,SAAS,EAAE,gEAAgE;oBAC3E,OAAO,EAAE,qBAAqB;oBAC9B,MAAM,EAAE,qBAAqB;oBAE7B,GAAG,CAAC,IAAI,KAAK,KAAK,IAAI,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC;oBAC7C,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;iBACpD;gBAED,oBAAC,YAAY,IAAC,cAAc,EAAC,GAAG,IAAE,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAgB,CACxE,CACF,CACF,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"min-max-button.js","sourceRoot":"","sources":["../../../src/components/min-max-button.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAOrC,MAAM,UAAU,YAAY,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAqB;IAC1E,OAAO,CACL,oBAAC,MAAM,IACL,OAAO,EAAE,GAAG,EAAE;YACZ,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,kCAAkC,CAAuB,CAAC;YAC9F,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,CAAC,WAAW,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;QAC5D,CAAC,EACD,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,IAEtC,QAAQ,CACF,CACV,CAAC;AACJ,CAAC"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
+
/* istanbul ignore file */
|
|
1
2
|
var _a, _b, _c, _d;
|
|
2
3
|
function getEnvVariable(name) {
|
|
3
4
|
return process.env[name];
|
|
4
5
|
}
|
|
6
|
+
// Optional env variables
|
|
5
7
|
const WORKOS_API_HOSTNAME = getEnvVariable('WORKOS_API_HOSTNAME');
|
|
6
8
|
const WORKOS_API_HTTPS = getEnvVariable('WORKOS_API_HTTPS');
|
|
7
|
-
const WORKOS_API_KEY = (_a = getEnvVariable('WORKOS_API_KEY')) !== null && _a !== void 0 ? _a : '';
|
|
8
9
|
const WORKOS_API_PORT = getEnvVariable('WORKOS_API_PORT');
|
|
9
|
-
const WORKOS_CLIENT_ID = (_b = getEnvVariable('WORKOS_CLIENT_ID')) !== null && _b !== void 0 ? _b : '';
|
|
10
10
|
const WORKOS_COOKIE_DOMAIN = getEnvVariable('WORKOS_COOKIE_DOMAIN');
|
|
11
11
|
const WORKOS_COOKIE_MAX_AGE = getEnvVariable('WORKOS_COOKIE_MAX_AGE');
|
|
12
12
|
const WORKOS_COOKIE_NAME = getEnvVariable('WORKOS_COOKIE_NAME');
|
|
13
|
+
// Required env variables
|
|
14
|
+
const WORKOS_API_KEY = (_a = getEnvVariable('WORKOS_API_KEY')) !== null && _a !== void 0 ? _a : '';
|
|
15
|
+
const WORKOS_CLIENT_ID = (_b = getEnvVariable('WORKOS_CLIENT_ID')) !== null && _b !== void 0 ? _b : '';
|
|
13
16
|
const WORKOS_COOKIE_PASSWORD = (_c = getEnvVariable('WORKOS_COOKIE_PASSWORD')) !== null && _c !== void 0 ? _c : '';
|
|
14
17
|
const WORKOS_REDIRECT_URI = (_d = process.env.NEXT_PUBLIC_WORKOS_REDIRECT_URI) !== null && _d !== void 0 ? _d : '';
|
|
15
18
|
export { WORKOS_API_HOSTNAME, WORKOS_API_HTTPS, WORKOS_API_KEY, WORKOS_API_PORT, WORKOS_CLIENT_ID, WORKOS_COOKIE_DOMAIN, WORKOS_COOKIE_MAX_AGE, WORKOS_COOKIE_NAME, WORKOS_COOKIE_PASSWORD, WORKOS_REDIRECT_URI, };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-variables.js","sourceRoot":"","sources":["../../src/env-variables.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"env-variables.js","sourceRoot":"","sources":["../../src/env-variables.ts"],"names":[],"mappings":"AAAA,0BAA0B;;AAE1B,SAAS,cAAc,CAAC,IAAY;IAClC,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED,yBAAyB;AACzB,MAAM,mBAAmB,GAAG,cAAc,CAAC,qBAAqB,CAAC,CAAC;AAClE,MAAM,gBAAgB,GAAG,cAAc,CAAC,kBAAkB,CAAC,CAAC;AAC5D,MAAM,eAAe,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAC;AAC1D,MAAM,oBAAoB,GAAG,cAAc,CAAC,sBAAsB,CAAC,CAAC;AACpE,MAAM,qBAAqB,GAAG,cAAc,CAAC,uBAAuB,CAAC,CAAC;AACtE,MAAM,kBAAkB,GAAG,cAAc,CAAC,oBAAoB,CAAC,CAAC;AAEhE,yBAAyB;AACzB,MAAM,cAAc,GAAG,MAAA,cAAc,CAAC,gBAAgB,CAAC,mCAAI,EAAE,CAAC;AAC9D,MAAM,gBAAgB,GAAG,MAAA,cAAc,CAAC,kBAAkB,CAAC,mCAAI,EAAE,CAAC;AAClE,MAAM,sBAAsB,GAAG,MAAA,cAAc,CAAC,wBAAwB,CAAC,mCAAI,EAAE,CAAC;AAC9E,MAAM,mBAAmB,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,+BAA+B,mCAAI,EAAE,CAAC;AAE9E,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,GACpB,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { handleAuth } from './authkit-callback-route.js';
|
|
2
|
-
import { authkitMiddleware } from './middleware.js';
|
|
3
|
-
import { withAuth, refreshSession
|
|
2
|
+
import { authkit, authkitMiddleware } from './middleware.js';
|
|
3
|
+
import { withAuth, refreshSession } from './session.js';
|
|
4
4
|
import { getSignInUrl, getSignUpUrl, signOut } from './auth.js';
|
|
5
|
-
import { Impersonation } from './impersonation.js';
|
|
6
|
-
import { AuthKitProvider } from './authkit-provider.js';
|
|
7
5
|
export { handleAuth,
|
|
8
6
|
//
|
|
9
|
-
authkitMiddleware,
|
|
7
|
+
authkitMiddleware, authkit,
|
|
10
8
|
//
|
|
11
|
-
getSignInUrl, getSignUpUrl, withAuth, refreshSession, signOut,
|
|
12
|
-
//
|
|
13
|
-
Impersonation, AuthKitProvider, };
|
|
9
|
+
getSignInUrl, getSignUpUrl, withAuth, refreshSession, signOut, };
|
|
14
10
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEhE,OAAO,EACL,UAAU;AACV,EAAE;AACF,iBAAiB,EACjB,OAAO;AACP,EAAE;AACF,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,OAAO,GACR,CAAC"}
|
package/dist/esm/middleware.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { updateSession } from './session.js';
|
|
1
|
+
import { updateSessionMiddleware, updateSession } from './session.js';
|
|
2
2
|
import { WORKOS_REDIRECT_URI } from './env-variables.js';
|
|
3
3
|
export function authkitMiddleware({ debug = false, middlewareAuth = { enabled: false, unauthenticatedPaths: [] }, redirectUri = WORKOS_REDIRECT_URI, signUpPaths = [], } = {}) {
|
|
4
4
|
return function (request) {
|
|
5
|
-
return
|
|
5
|
+
return updateSessionMiddleware(request, debug, middlewareAuth, redirectUri, signUpPaths);
|
|
6
6
|
};
|
|
7
7
|
}
|
|
8
|
+
export async function authkit(request, options = {}) {
|
|
9
|
+
return await updateSession(request, options);
|
|
10
|
+
}
|
|
8
11
|
//# sourceMappingURL=middleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,MAAM,UAAU,iBAAiB,CAAC,EAChC,KAAK,GAAG,KAAK,EACb,cAAc,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,EAAE,EAAE,EAC7D,WAAW,GAAG,mBAAmB,EACjC,WAAW,GAAG,EAAE,MACY,EAAE;IAC9B,OAAO,UAAU,OAAO;QACtB,OAAO,uBAAuB,CAAC,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;IAC3F,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAoB,EAAE,UAA0B,EAAE;IAC9E,OAAO,MAAM,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC/C,CAAC"}
|