@workos-inc/authkit-nextjs 0.10.0 → 0.11.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 +56 -10
- package/dist/esm/actions.js +10 -0
- package/dist/esm/actions.js.map +1 -0
- package/dist/esm/auth.js +18 -0
- package/dist/esm/auth.js.map +1 -0
- package/dist/{cjs → esm}/authkit-callback-route.js +14 -17
- package/dist/esm/authkit-callback-route.js.map +1 -0
- package/dist/{cjs/provider.js → esm/authkit-provider.js} +14 -15
- package/dist/esm/authkit-provider.js.map +1 -0
- package/dist/{cjs → esm}/button.js +2 -6
- package/dist/esm/button.js.map +1 -0
- package/dist/{cjs → esm}/cookie.d.ts +1 -2
- package/dist/esm/cookie.js +16 -0
- package/dist/esm/cookie.js.map +1 -0
- package/dist/{cjs → esm}/env-variables.d.ts +6 -5
- package/dist/esm/env-variables.js +16 -0
- package/dist/esm/env-variables.js.map +1 -0
- package/dist/esm/get-authorization-url.js +17 -0
- package/dist/esm/get-authorization-url.js.map +1 -0
- package/dist/{cjs → esm}/impersonation.js +13 -18
- package/dist/esm/impersonation.js.map +1 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/{cjs → esm}/interfaces.d.ts +2 -0
- package/dist/esm/interfaces.js +2 -0
- package/dist/{cjs → esm}/middleware.d.ts +1 -1
- package/dist/esm/middleware.js +7 -0
- package/dist/esm/middleware.js.map +1 -0
- package/dist/esm/min-max-button.js +10 -0
- package/dist/esm/min-max-button.js.map +1 -0
- package/dist/esm/session.d.ts +34 -0
- package/dist/{cjs → esm}/session.js +83 -59
- package/dist/esm/session.js.map +1 -0
- package/dist/{cjs → esm}/workos.d.ts +1 -1
- package/dist/esm/workos.js +16 -0
- package/dist/esm/workos.js.map +1 -0
- package/package.json +6 -6
- package/src/auth.ts +4 -1
- package/src/authkit-callback-route.ts +4 -2
- package/src/{provider.tsx → authkit-provider.tsx} +8 -4
- package/src/cookie.ts +1 -2
- package/src/env-variables.ts +16 -26
- package/src/get-authorization-url.ts +4 -1
- package/src/impersonation.tsx +2 -2
- package/src/index.ts +4 -3
- package/src/interfaces.ts +2 -0
- package/src/middleware.ts +2 -1
- package/src/session.ts +57 -13
- package/src/workos.ts +2 -2
- package/dist/cjs/actions.js +0 -14
- package/dist/cjs/actions.js.map +0 -1
- package/dist/cjs/auth.js +0 -21
- package/dist/cjs/auth.js.map +0 -1
- package/dist/cjs/authkit-callback-route.js.map +0 -1
- package/dist/cjs/button.js.map +0 -1
- package/dist/cjs/cookie.js +0 -21
- package/dist/cjs/cookie.js.map +0 -1
- package/dist/cjs/env-variables.js +0 -35
- package/dist/cjs/env-variables.js.map +0 -1
- package/dist/cjs/get-authorization-url.js +0 -18
- package/dist/cjs/get-authorization-url.js.map +0 -1
- package/dist/cjs/impersonation.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -7
- package/dist/cjs/index.js +0 -19
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/interfaces.js +0 -3
- package/dist/cjs/middleware.js +0 -11
- package/dist/cjs/middleware.js.map +0 -1
- package/dist/cjs/min-max-button.js +0 -15
- package/dist/cjs/min-max-button.js.map +0 -1
- package/dist/cjs/provider.js.map +0 -1
- package/dist/cjs/session.d.ts +0 -20
- package/dist/cjs/session.js.map +0 -1
- package/dist/cjs/workos.js +0 -19
- package/dist/cjs/workos.js.map +0 -1
- /package/dist/{cjs → esm}/actions.d.ts +0 -0
- /package/dist/{cjs → esm}/auth.d.ts +0 -0
- /package/dist/{cjs → esm}/authkit-callback-route.d.ts +0 -0
- /package/dist/{cjs/provider.d.ts → esm/authkit-provider.d.ts} +0 -0
- /package/dist/{cjs → esm}/button.d.ts +0 -0
- /package/dist/{cjs → esm}/get-authorization-url.d.ts +0 -0
- /package/dist/{cjs → esm}/impersonation.d.ts +0 -0
- /package/dist/{cjs → esm}/interfaces.js.map +0 -0
- /package/dist/{cjs → esm}/min-max-button.d.ts +0 -0
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
The AuthKit library for Next.js provides convenient helpers for authentication and session management using WorkOS & AuthKit with Next.js.
|
|
4
4
|
|
|
5
|
+
> Note: This library is intended for use with the Next.js App Router.
|
|
6
|
+
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
Install the package with:
|
|
@@ -29,8 +31,8 @@ Make sure the following values are present in your `.env.local` environment vari
|
|
|
29
31
|
```sh
|
|
30
32
|
WORKOS_CLIENT_ID="client_..." # retrieved from the WorkOS dashboard
|
|
31
33
|
WORKOS_API_KEY="sk_test_..." # retrieved from the WorkOS dashboard
|
|
32
|
-
WORKOS_REDIRECT_URI="http://localhost:3000/callback" # configured in the WorkOS dashboard
|
|
33
34
|
WORKOS_COOKIE_PASSWORD="<your password>" # generate a secure password here
|
|
35
|
+
NEXT_PUBLIC_WORKOS_REDIRECT_URI="http://localhost:3000/callback" # configured in the WorkOS dashboard
|
|
34
36
|
```
|
|
35
37
|
|
|
36
38
|
`WORKOS_COOKIE_PASSWORD` is the private key used to encrypt the session cookie. It has to be at least 32 characters long. You can use the [1Password generator](https://1password.com/password-generator/) or the `openssl` library to generate a strong password via the command line:
|
|
@@ -46,7 +48,9 @@ To use the `signOut` method, you'll need to set your app's homepage in your Work
|
|
|
46
48
|
Certain environment variables are optional and can be used to debug or configure cookie settings.
|
|
47
49
|
|
|
48
50
|
```sh
|
|
49
|
-
WORKOS_COOKIE_MAX_AGE='600' # maximum age of the cookie in seconds. Defaults to
|
|
51
|
+
WORKOS_COOKIE_MAX_AGE='600' # maximum age of the cookie in seconds. Defaults to 400 days, the maximum allowed in Chrome
|
|
52
|
+
WORKOS_COOKIE_DOMAIN='example.com'
|
|
53
|
+
WORKOS_COOKIE_NAME='authkit-cookie'
|
|
50
54
|
WORKOS_API_HOSTNAME='api.workos.com' # base WorkOS API URL
|
|
51
55
|
WORKOS_API_HTTPS=true # whether to use HTTPS in API calls
|
|
52
56
|
WORKOS_API_PORT=3000 # port to use for API calls
|
|
@@ -90,6 +94,24 @@ export default authkitMiddleware();
|
|
|
90
94
|
export const config = { matcher: ['/', '/admin'] };
|
|
91
95
|
```
|
|
92
96
|
|
|
97
|
+
#### Custom redirect URI
|
|
98
|
+
|
|
99
|
+
In cases where you need your redirect URI to be set dynamically (e.g. Vercel preview deployments), use the `redirectUri` option in `authkitMiddleware`:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import { authkitMiddleware } from '@workos-inc/authkit-nextjs';
|
|
103
|
+
|
|
104
|
+
export default authkitMiddleware({
|
|
105
|
+
redirectUri: 'https://foo.example.com/callback',
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Match against pages that require auth
|
|
109
|
+
// Leave this out if you want auth on every resource (including images, css etc.)
|
|
110
|
+
export const config = { matcher: ['/', '/admin'] };
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Custom redirect URIs will be used over a redirect URI configured in the environment variables.
|
|
114
|
+
|
|
93
115
|
## Usage
|
|
94
116
|
|
|
95
117
|
### Wrap your app in `AuthKitProvider`
|
|
@@ -112,15 +134,15 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
112
134
|
|
|
113
135
|
### Get the current user
|
|
114
136
|
|
|
115
|
-
For pages where you want to display a signed-in and signed-out view, use `
|
|
137
|
+
For pages where you want to display a signed-in and signed-out view, use `withAuth` to retrieve the user profile from WorkOS.
|
|
116
138
|
|
|
117
139
|
```jsx
|
|
118
140
|
import Link from 'next/link';
|
|
119
|
-
import { getSignInUrl, getSignUpUrl,
|
|
141
|
+
import { getSignInUrl, getSignUpUrl, withAuth, signOut } from '@workos-inc/authkit-nextjs';
|
|
120
142
|
|
|
121
143
|
export default async function HomePage() {
|
|
122
144
|
// Retrieves the user from the session or returns `null` if no user is signed in
|
|
123
|
-
const { user } = await
|
|
145
|
+
const { user } = await withAuth();
|
|
124
146
|
|
|
125
147
|
if (!user) {
|
|
126
148
|
// Get the URL to redirect the user to AuthKit to sign in
|
|
@@ -156,14 +178,14 @@ export default async function HomePage() {
|
|
|
156
178
|
For pages where a signed-in user is mandatory, you can use the `ensureSignedIn` option:
|
|
157
179
|
|
|
158
180
|
```jsx
|
|
159
|
-
const { user } = await
|
|
181
|
+
const { user } = await withAuth({ ensureSignedIn: true });
|
|
160
182
|
```
|
|
161
183
|
|
|
162
184
|
Enabling `ensureSignedIn` will redirect users to AuthKit if they attempt to access the page without being authenticated.
|
|
163
185
|
|
|
164
186
|
### Middleware auth
|
|
165
187
|
|
|
166
|
-
The default behavior of this library is to request authentication via the `
|
|
188
|
+
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:
|
|
167
189
|
|
|
168
190
|
```ts
|
|
169
191
|
import { authkitMiddleware } from '@workos-inc/authkit-nextjs';
|
|
@@ -184,6 +206,30 @@ In the above example the `/admin` page will require a user to be signed in, wher
|
|
|
184
206
|
|
|
185
207
|
`unauthenticatedPaths` uses the same glob logic as the [Next.js matcher](https://nextjs.org/docs/pages/building-your-application/routing/middleware#matcher).
|
|
186
208
|
|
|
209
|
+
### Retrieve session in middleware
|
|
210
|
+
|
|
211
|
+
Sometimes it's useful to check the user session if you want to compose custom middleware. The `getSession` helper method will retrieve the session from the cookie and verify the access token.
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
import { authkitMiddleware, getSession } from '@workos-inc/authkit-nextjs';
|
|
215
|
+
import { NextRequest } from 'next/server';
|
|
216
|
+
|
|
217
|
+
export default async function middleware(request: NextRequest) {
|
|
218
|
+
// authkitMiddleware will handle refreshing the session if the access token has expired
|
|
219
|
+
const response = await authkitMiddleware()(request);
|
|
220
|
+
|
|
221
|
+
// If session is undefined, the user is not authenticated
|
|
222
|
+
const session = await getSession(response);
|
|
223
|
+
|
|
224
|
+
// ...add additional middleware logic here
|
|
225
|
+
|
|
226
|
+
return response;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Match against pages that require auth
|
|
230
|
+
export const config = { matcher: ['/', '/account/:path*'] };
|
|
231
|
+
```
|
|
232
|
+
|
|
187
233
|
### Signing out
|
|
188
234
|
|
|
189
235
|
Use the `signOut` method to sign out the current logged in user and redirect to your app's homepage. The homepage redirect is set in your WorkOS dashboard settings under "Redirect".
|
|
@@ -211,10 +257,10 @@ export default function App() {
|
|
|
211
257
|
Sometimes it is useful to obtain the access token directly, for instance to make API requests to another service.
|
|
212
258
|
|
|
213
259
|
```jsx
|
|
214
|
-
import {
|
|
260
|
+
import { withAuth } from '@workos-inc/authkit-nextjs';
|
|
215
261
|
|
|
216
262
|
export default async function HomePage() {
|
|
217
|
-
const { accessToken } = await
|
|
263
|
+
const { accessToken } = await withAuth();
|
|
218
264
|
|
|
219
265
|
if (!accessToken) {
|
|
220
266
|
return <div>Not signed in</div>;
|
|
@@ -250,4 +296,4 @@ export default authkitMiddleware({ debug: true });
|
|
|
250
296
|
|
|
251
297
|
#### NEXT_REDIRECT error when using try/catch blocks
|
|
252
298
|
|
|
253
|
-
Wrapping a `
|
|
299
|
+
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).
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
/**
|
|
3
|
+
* This action is only accessible to authenticated users,
|
|
4
|
+
* there is no need to check the session here as the middleware will
|
|
5
|
+
* be responsible for that.
|
|
6
|
+
*/
|
|
7
|
+
export const checkSessionAction = async () => {
|
|
8
|
+
return true;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/actions.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,IAAI,EAAE;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
package/dist/esm/auth.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
import { getAuthorizationUrl } from './get-authorization-url.js';
|
|
3
|
+
import { cookies } from 'next/headers';
|
|
4
|
+
import { terminateSession } from './session.js';
|
|
5
|
+
import { WORKOS_COOKIE_NAME } from './env-variables.js';
|
|
6
|
+
async function getSignInUrl({ organizationId } = {}) {
|
|
7
|
+
return getAuthorizationUrl({ organizationId, screenHint: 'sign-in' });
|
|
8
|
+
}
|
|
9
|
+
async function getSignUpUrl() {
|
|
10
|
+
return getAuthorizationUrl({ screenHint: 'sign-up' });
|
|
11
|
+
}
|
|
12
|
+
async function signOut() {
|
|
13
|
+
const cookieName = WORKOS_COOKIE_NAME || 'wos-session';
|
|
14
|
+
cookies().delete(cookieName);
|
|
15
|
+
await terminateSession();
|
|
16
|
+
}
|
|
17
|
+
export { getSignInUrl, getSignUpUrl, signOut };
|
|
18
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/auth.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,KAAK,UAAU,YAAY,CAAC,EAAE,cAAc,KAAkC,EAAE;IAC9E,OAAO,mBAAmB,CAAC,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC;AACxE,CAAC;AAED,KAAK,UAAU,YAAY;IACzB,OAAO,mBAAmB,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC;AACxD,CAAC;AAED,KAAK,UAAU,OAAO;IACpB,MAAM,UAAU,GAAG,kBAAkB,IAAI,aAAa,CAAC;IACvD,OAAO,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC7B,MAAM,gBAAgB,EAAE,CAAC;AAC3B,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const session_js_1 = require("./session.js");
|
|
9
|
-
const cookie_js_1 = require("./cookie.js");
|
|
10
|
-
function handleAuth(options = {}) {
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
import { cookies } from 'next/headers';
|
|
3
|
+
import { workos } from './workos.js';
|
|
4
|
+
import { WORKOS_CLIENT_ID, WORKOS_COOKIE_NAME } from './env-variables.js';
|
|
5
|
+
import { encryptSession } from './session.js';
|
|
6
|
+
import { cookieOptions } from './cookie.js';
|
|
7
|
+
export function handleAuth(options = {}) {
|
|
11
8
|
const { returnPathname: returnPathnameOption = '/' } = options;
|
|
12
9
|
return async function GET(request) {
|
|
13
10
|
const code = request.nextUrl.searchParams.get('code');
|
|
@@ -16,8 +13,8 @@ function handleAuth(options = {}) {
|
|
|
16
13
|
if (code) {
|
|
17
14
|
try {
|
|
18
15
|
// Use the code returned to us by AuthKit and authenticate the user with WorkOS
|
|
19
|
-
const { accessToken, refreshToken, user, impersonator } = await
|
|
20
|
-
clientId:
|
|
16
|
+
const { accessToken, refreshToken, user, impersonator } = await workos.userManagement.authenticateWithCode({
|
|
17
|
+
clientId: WORKOS_CLIENT_ID,
|
|
21
18
|
code,
|
|
22
19
|
});
|
|
23
20
|
const url = request.nextUrl.clone();
|
|
@@ -37,13 +34,14 @@ function handleAuth(options = {}) {
|
|
|
37
34
|
else {
|
|
38
35
|
url.pathname = returnPathname;
|
|
39
36
|
}
|
|
40
|
-
const response =
|
|
37
|
+
const response = NextResponse.redirect(url);
|
|
41
38
|
if (!accessToken || !refreshToken)
|
|
42
39
|
throw new Error('response is missing tokens');
|
|
43
40
|
// The refreshToken should never be accesible publicly, hence why we encrypt it in the cookie session
|
|
44
41
|
// Alternatively you could persist the refresh token in a backend database
|
|
45
|
-
const session = await
|
|
46
|
-
|
|
42
|
+
const session = await encryptSession({ accessToken, refreshToken, user, impersonator });
|
|
43
|
+
const cookieName = WORKOS_COOKIE_NAME || 'wos-session';
|
|
44
|
+
cookies().set(cookieName, session, cookieOptions);
|
|
47
45
|
return response;
|
|
48
46
|
}
|
|
49
47
|
catch (error) {
|
|
@@ -57,7 +55,7 @@ function handleAuth(options = {}) {
|
|
|
57
55
|
return errorResponse();
|
|
58
56
|
};
|
|
59
57
|
function errorResponse() {
|
|
60
|
-
return
|
|
58
|
+
return NextResponse.json({
|
|
61
59
|
error: {
|
|
62
60
|
message: 'Something went wrong',
|
|
63
61
|
description: 'Couldn’t sign in. If you are not sure what happened, please contact your organization admin.',
|
|
@@ -65,5 +63,4 @@ function handleAuth(options = {}) {
|
|
|
65
63
|
}, { status: 500 });
|
|
66
64
|
}
|
|
67
65
|
}
|
|
68
|
-
exports.handleAuth = handleAuth;
|
|
69
66
|
//# sourceMappingURL=authkit-callback-route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authkit-callback-route.js","sourceRoot":"","sources":["../../src/authkit-callback-route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;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CAAC,CAAC;IAEF,SAAS,aAAa;QACpB,OAAO,YAAY,CAAC,IAAI,CACtB;YACE,KAAK,EAAE;gBACL,OAAO,EAAE,sBAAsB;gBAC/B,WAAW,EAAE,8FAA8F;aAC5G;SACF,EACD,EAAE,MAAM,EAAE,GAAG,EAAE,CAChB,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
'use client';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const React = tslib_1.__importStar(require("react"));
|
|
7
|
-
const actions_js_1 = require("./actions.js");
|
|
8
|
-
const AuthKitProvider = ({ children, onSessionExpired }) => {
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { checkSessionAction } from './actions.js';
|
|
4
|
+
export const AuthKitProvider = ({ children, onSessionExpired }) => {
|
|
9
5
|
React.useEffect(() => {
|
|
10
6
|
// Return early if the session expired checks are disabled.
|
|
11
7
|
if (onSessionExpired === false) {
|
|
@@ -22,17 +18,21 @@ const AuthKitProvider = ({ children, onSessionExpired }) => {
|
|
|
22
18
|
if (document.visibilityState === 'visible') {
|
|
23
19
|
visibilityChangedCalled = true;
|
|
24
20
|
try {
|
|
25
|
-
const hasSession = await
|
|
21
|
+
const hasSession = await checkSessionAction();
|
|
26
22
|
if (!hasSession) {
|
|
27
23
|
throw new Error('Session expired');
|
|
28
24
|
}
|
|
29
25
|
}
|
|
30
26
|
catch (error) {
|
|
31
|
-
if
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
// 'Failed to fetch' is the error we are looking for if the action fails
|
|
28
|
+
// If any other error happens, for other reasons, we should not reload the page
|
|
29
|
+
if (error instanceof Error && error.message.includes('Failed to fetch')) {
|
|
30
|
+
if (onSessionExpired) {
|
|
31
|
+
onSessionExpired();
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
window.location.reload();
|
|
35
|
+
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
finally {
|
|
@@ -49,5 +49,4 @@ const AuthKitProvider = ({ children, onSessionExpired }) => {
|
|
|
49
49
|
}, [onSessionExpired]);
|
|
50
50
|
return React.createElement(React.Fragment, null, children);
|
|
51
51
|
};
|
|
52
|
-
|
|
53
|
-
//# sourceMappingURL=provider.js.map
|
|
52
|
+
//# sourceMappingURL=authkit-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authkit-provider.js","sourceRoot":"","sources":["../../src/authkit-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAWlD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAAE,QAAQ,EAAE,gBAAgB,EAAwB,EAAE,EAAE;IACtF,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,2DAA2D;QAC3D,IAAI,gBAAgB,KAAK,KAAK,EAAE,CAAC;YAC/B,OAAO;QACT,CAAC;QAED,IAAI,uBAAuB,GAAG,KAAK,CAAC;QAEpC,MAAM,sBAAsB,GAAG,KAAK,IAAI,EAAE;YACxC,IAAI,uBAAuB,EAAE,CAAC;gBAC5B,OAAO;YACT,CAAC;YAED,oGAAoG;YACpG,qFAAqF;YACrF,oGAAoG;YACpG,IAAI,QAAQ,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;gBAC3C,uBAAuB,GAAG,IAAI,CAAC;gBAE/B,IAAI,CAAC;oBACH,MAAM,UAAU,GAAG,MAAM,kBAAkB,EAAE,CAAC;oBAC9C,IAAI,CAAC,UAAU,EAAE,CAAC;wBAChB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;oBACrC,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,wEAAwE;oBACxE,+EAA+E;oBAC/E,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC;wBACxE,IAAI,gBAAgB,EAAE,CAAC;4BACrB,gBAAgB,EAAE,CAAC;wBACrB,CAAC;6BAAM,CAAC;4BACN,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;wBAC3B,CAAC;oBACH,CAAC;gBACH,CAAC;wBAAS,CAAC;oBACT,uBAAuB,GAAG,KAAK,CAAC;gBAClC,CAAC;YACH,CAAC;QACH,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,sBAAsB,CAAC,CAAC;QACpE,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,sBAAsB,CAAC,CAAC;QAEzD,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,sBAAsB,CAAC,CAAC;YAC5D,MAAM,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,sBAAsB,CAAC,CAAC;QACzE,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEvB,OAAO,0CAAG,QAAQ,CAAI,CAAC;AACzB,CAAC,CAAC"}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Button = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const React = tslib_1.__importStar(require("react"));
|
|
1
|
+
import * as React from 'react';
|
|
6
2
|
const Button = React.forwardRef((props, forwardedRef) => {
|
|
7
3
|
return (React.createElement("button", { ref: forwardedRef, type: "button", ...props, style: {
|
|
8
4
|
display: 'inline-flex',
|
|
@@ -20,6 +16,6 @@ const Button = React.forwardRef((props, forwardedRef) => {
|
|
|
20
16
|
...props.style,
|
|
21
17
|
} }));
|
|
22
18
|
});
|
|
23
|
-
exports.Button = Button;
|
|
24
19
|
Button.displayName = 'Button';
|
|
20
|
+
export { Button };
|
|
25
21
|
//# sourceMappingURL=button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button.js","sourceRoot":"","sources":["../../src/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,4 +1,3 @@
|
|
|
1
|
-
declare const cookieName = "wos-session";
|
|
2
1
|
declare const cookieOptions: {
|
|
3
2
|
path: string;
|
|
4
3
|
httpOnly: boolean;
|
|
@@ -7,4 +6,4 @@ declare const cookieOptions: {
|
|
|
7
6
|
maxAge: number;
|
|
8
7
|
domain: string | undefined;
|
|
9
8
|
};
|
|
10
|
-
export {
|
|
9
|
+
export { cookieOptions };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { WORKOS_REDIRECT_URI, WORKOS_COOKIE_MAX_AGE, WORKOS_COOKIE_DOMAIN } from './env-variables.js';
|
|
2
|
+
const redirectUrl = new URL(WORKOS_REDIRECT_URI);
|
|
3
|
+
const isSecureProtocol = redirectUrl.protocol === 'https:';
|
|
4
|
+
const cookieOptions = {
|
|
5
|
+
path: '/',
|
|
6
|
+
httpOnly: true,
|
|
7
|
+
secure: isSecureProtocol,
|
|
8
|
+
sameSite: 'lax',
|
|
9
|
+
// Defaults to 400 days, the maximum allowed by Chrome
|
|
10
|
+
// It's fine to have a long cookie expiry date as the access/refresh tokens
|
|
11
|
+
// act as the actual time-limited aspects of the session.
|
|
12
|
+
maxAge: WORKOS_COOKIE_MAX_AGE ? parseInt(WORKOS_COOKIE_MAX_AGE, 10) : 60 * 60 * 24 * 400,
|
|
13
|
+
domain: WORKOS_COOKIE_DOMAIN,
|
|
14
|
+
};
|
|
15
|
+
export { cookieOptions };
|
|
16
|
+
//# sourceMappingURL=cookie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../src/cookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAEtG,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,mBAAmB,CAAC,CAAC;AACjD,MAAM,gBAAgB,GAAG,WAAW,CAAC,QAAQ,KAAK,QAAQ,CAAC;AAE3D,MAAM,aAAa,GAAG;IACpB,IAAI,EAAE,GAAG;IACT,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,gBAAgB;IACxB,QAAQ,EAAE,KAAc;IACxB,sDAAsD;IACtD,2EAA2E;IAC3E,yDAAyD;IACzD,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC,QAAQ,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG;IACxF,MAAM,EAAE,oBAAoB;CAC7B,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
declare const WORKOS_CLIENT_ID: string;
|
|
2
|
-
declare const WORKOS_API_KEY: string;
|
|
3
|
-
declare const WORKOS_REDIRECT_URI: string;
|
|
4
|
-
declare const WORKOS_COOKIE_PASSWORD: string;
|
|
5
1
|
declare const WORKOS_API_HOSTNAME: string | undefined;
|
|
6
2
|
declare const WORKOS_API_HTTPS: string | undefined;
|
|
3
|
+
declare const WORKOS_API_KEY: string;
|
|
7
4
|
declare const WORKOS_API_PORT: string | undefined;
|
|
5
|
+
declare const WORKOS_CLIENT_ID: string;
|
|
8
6
|
declare const WORKOS_COOKIE_DOMAIN: string | undefined;
|
|
9
7
|
declare const WORKOS_COOKIE_MAX_AGE: string | undefined;
|
|
10
|
-
|
|
8
|
+
declare const WORKOS_COOKIE_NAME: string | undefined;
|
|
9
|
+
declare const WORKOS_COOKIE_PASSWORD: string;
|
|
10
|
+
declare const WORKOS_REDIRECT_URI: string;
|
|
11
|
+
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, };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var _a, _b, _c, _d;
|
|
2
|
+
function getEnvVariable(name) {
|
|
3
|
+
return process.env[name];
|
|
4
|
+
}
|
|
5
|
+
const WORKOS_API_HOSTNAME = getEnvVariable('WORKOS_API_HOSTNAME');
|
|
6
|
+
const WORKOS_API_HTTPS = getEnvVariable('WORKOS_API_HTTPS');
|
|
7
|
+
const WORKOS_API_KEY = (_a = getEnvVariable('WORKOS_API_KEY')) !== null && _a !== void 0 ? _a : '';
|
|
8
|
+
const WORKOS_API_PORT = getEnvVariable('WORKOS_API_PORT');
|
|
9
|
+
const WORKOS_CLIENT_ID = (_b = getEnvVariable('WORKOS_CLIENT_ID')) !== null && _b !== void 0 ? _b : '';
|
|
10
|
+
const WORKOS_COOKIE_DOMAIN = getEnvVariable('WORKOS_COOKIE_DOMAIN');
|
|
11
|
+
const WORKOS_COOKIE_MAX_AGE = getEnvVariable('WORKOS_COOKIE_MAX_AGE');
|
|
12
|
+
const WORKOS_COOKIE_NAME = getEnvVariable('WORKOS_COOKIE_NAME');
|
|
13
|
+
const WORKOS_COOKIE_PASSWORD = (_c = getEnvVariable('WORKOS_COOKIE_PASSWORD')) !== null && _c !== void 0 ? _c : '';
|
|
14
|
+
const WORKOS_REDIRECT_URI = (_d = getEnvVariable('NEXT_PUBLIC_WORKOS_REDIRECT_URI')) !== null && _d !== void 0 ? _d : '';
|
|
15
|
+
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, };
|
|
16
|
+
//# sourceMappingURL=env-variables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-variables.js","sourceRoot":"","sources":["../../src/env-variables.ts"],"names":[],"mappings":";AAAA,SAAS,cAAc,CAAC,IAAY;IAClC,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,mBAAmB,GAAG,cAAc,CAAC,qBAAqB,CAAC,CAAC;AAClE,MAAM,gBAAgB,GAAG,cAAc,CAAC,kBAAkB,CAAC,CAAC;AAC5D,MAAM,cAAc,GAAG,MAAA,cAAc,CAAC,gBAAgB,CAAC,mCAAI,EAAE,CAAC;AAC9D,MAAM,eAAe,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAC;AAC1D,MAAM,gBAAgB,GAAG,MAAA,cAAc,CAAC,kBAAkB,CAAC,mCAAI,EAAE,CAAC;AAClE,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;AAChE,MAAM,sBAAsB,GAAG,MAAA,cAAc,CAAC,wBAAwB,CAAC,mCAAI,EAAE,CAAC;AAC9E,MAAM,mBAAmB,GAAG,MAAA,cAAc,CAAC,iCAAiC,CAAC,mCAAI,EAAE,CAAC;AAEpF,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,GACpB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { workos } from './workos.js';
|
|
2
|
+
import { WORKOS_CLIENT_ID, WORKOS_REDIRECT_URI } from './env-variables.js';
|
|
3
|
+
import { headers } from 'next/headers';
|
|
4
|
+
async function getAuthorizationUrl(options = {}) {
|
|
5
|
+
const { returnPathname, screenHint, organizationId } = options;
|
|
6
|
+
const redirectUri = headers().get('x-redirect-uri');
|
|
7
|
+
return workos.userManagement.getAuthorizationUrl({
|
|
8
|
+
provider: 'authkit',
|
|
9
|
+
clientId: WORKOS_CLIENT_ID,
|
|
10
|
+
redirectUri: redirectUri !== null && redirectUri !== void 0 ? redirectUri : WORKOS_REDIRECT_URI,
|
|
11
|
+
state: returnPathname ? btoa(JSON.stringify({ returnPathname })) : undefined,
|
|
12
|
+
screenHint,
|
|
13
|
+
organizationId,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export { getAuthorizationUrl };
|
|
17
|
+
//# sourceMappingURL=get-authorization-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-authorization-url.js","sourceRoot":"","sources":["../../src/get-authorization-url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE3E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,KAAK,UAAU,mBAAmB,CAAC,UAA6B,EAAE;IAChE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;IAE/D,MAAM,WAAW,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAEpD,OAAO,MAAM,CAAC,cAAc,CAAC,mBAAmB,CAAC;QAC/C,QAAQ,EAAE,SAAS;QACnB,QAAQ,EAAE,gBAAgB;QAC1B,WAAW,EAAE,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,mBAAmB;QAC/C,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;QAC5E,UAAU;QACV,cAAc;KACf,CAAC,CAAC;AACL,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const button_js_1 = require("./button.js");
|
|
10
|
-
const min_max_button_js_1 = require("./min-max-button.js");
|
|
11
|
-
async function Impersonation({ side = 'bottom', ...props }) {
|
|
12
|
-
const { impersonator, user, organizationId } = await (0, session_js_1.getUser)();
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { withAuth } from './session.js';
|
|
3
|
+
import { signOut } from './auth.js';
|
|
4
|
+
import { workos } from './workos.js';
|
|
5
|
+
import { Button } from './button.js';
|
|
6
|
+
import { MinMaxButton } from './min-max-button.js';
|
|
7
|
+
export async function Impersonation({ side = 'bottom', ...props }) {
|
|
8
|
+
const { impersonator, user, organizationId } = await withAuth();
|
|
13
9
|
if (!impersonator)
|
|
14
10
|
return null;
|
|
15
|
-
const organization = organizationId ? await
|
|
11
|
+
const organization = organizationId ? await workos.organizations.getOrganization(organizationId) : null;
|
|
16
12
|
return (React.createElement("div", { ...props, "data-workos-impersonation-root": "", style: {
|
|
17
13
|
'position': 'fixed',
|
|
18
14
|
'inset': 0,
|
|
@@ -52,7 +48,7 @@ async function Impersonation({ side = 'bottom', ...props }) {
|
|
|
52
48
|
} },
|
|
53
49
|
React.createElement("form", { action: async () => {
|
|
54
50
|
'use server';
|
|
55
|
-
await
|
|
51
|
+
await signOut();
|
|
56
52
|
}, style: {
|
|
57
53
|
display: 'flex',
|
|
58
54
|
alignItems: 'baseline',
|
|
@@ -96,8 +92,8 @@ async function Impersonation({ side = 'bottom', ...props }) {
|
|
|
96
92
|
"within the ",
|
|
97
93
|
React.createElement("b", null, organization.name),
|
|
98
94
|
" organization"))),
|
|
99
|
-
React.createElement(
|
|
100
|
-
React.createElement(
|
|
95
|
+
React.createElement(Button, { type: "submit", style: { marginLeft: 'calc(var(--wi-s) * 2)', marginRight: 'var(--wi-s)' } }, "Stop"),
|
|
96
|
+
React.createElement(MinMaxButton, { minimizedValue: "1" }, side === 'top' ? '↗' : '↘')),
|
|
101
97
|
React.createElement("div", { style: {
|
|
102
98
|
padding: 'var(--wi-s)',
|
|
103
99
|
position: 'fixed',
|
|
@@ -113,7 +109,6 @@ async function Impersonation({ side = 'bottom', ...props }) {
|
|
|
113
109
|
...(side === 'top' && { top: 'var(--wi-s)' }),
|
|
114
110
|
...(side === 'bottom' && { bottom: 'var(--wi-s)' }),
|
|
115
111
|
} },
|
|
116
|
-
React.createElement(
|
|
112
|
+
React.createElement(MinMaxButton, { minimizedValue: "0" }, side === 'top' ? '↙' : '↖')))));
|
|
117
113
|
}
|
|
118
|
-
exports.Impersonation = Impersonation;
|
|
119
114
|
//# sourceMappingURL=impersonation.js.map
|
|
@@ -0,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,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,7 @@
|
|
|
1
|
+
import { handleAuth } from './authkit-callback-route.js';
|
|
2
|
+
import { authkitMiddleware } from './middleware.js';
|
|
3
|
+
import { withAuth, refreshSession, getSession } from './session.js';
|
|
4
|
+
import { getSignInUrl, getSignUpUrl, signOut } from './auth.js';
|
|
5
|
+
import { Impersonation } from './impersonation.js';
|
|
6
|
+
import { AuthKitProvider } from './authkit-provider.js';
|
|
7
|
+
export { handleAuth, authkitMiddleware, getSession, getSignInUrl, getSignUpUrl, withAuth, refreshSession, signOut, Impersonation, AuthKitProvider, };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { handleAuth } from './authkit-callback-route.js';
|
|
2
|
+
import { authkitMiddleware } from './middleware.js';
|
|
3
|
+
import { withAuth, refreshSession, getSession } from './session.js';
|
|
4
|
+
import { getSignInUrl, getSignUpUrl, signOut } from './auth.js';
|
|
5
|
+
import { Impersonation } from './impersonation.js';
|
|
6
|
+
import { AuthKitProvider } from './authkit-provider.js';
|
|
7
|
+
export { handleAuth,
|
|
8
|
+
//
|
|
9
|
+
authkitMiddleware, getSession,
|
|
10
|
+
//
|
|
11
|
+
getSignInUrl, getSignUpUrl, withAuth, refreshSession, signOut,
|
|
12
|
+
//
|
|
13
|
+
Impersonation, AuthKitProvider, };
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;AACpD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EACL,UAAU;AACV,EAAE;AACF,iBAAiB,EACjB,UAAU;AACV,EAAE;AACF,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,OAAO;AACP,EAAE;AACF,aAAa,EACb,eAAe,GAChB,CAAC"}
|
|
@@ -39,6 +39,7 @@ export interface GetAuthURLOptions {
|
|
|
39
39
|
screenHint?: 'sign-up' | 'sign-in';
|
|
40
40
|
returnPathname?: string;
|
|
41
41
|
organizationId?: string;
|
|
42
|
+
redirectUri?: string;
|
|
42
43
|
}
|
|
43
44
|
export interface AuthkitMiddlewareAuth {
|
|
44
45
|
enabled: boolean;
|
|
@@ -47,4 +48,5 @@ export interface AuthkitMiddlewareAuth {
|
|
|
47
48
|
export interface AuthkitMiddlewareOptions {
|
|
48
49
|
debug?: boolean;
|
|
49
50
|
middlewareAuth?: AuthkitMiddlewareAuth;
|
|
51
|
+
redirectUri?: string;
|
|
50
52
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { NextMiddleware } from 'next/server';
|
|
2
2
|
import { AuthkitMiddlewareOptions } from './interfaces.js';
|
|
3
|
-
export declare function authkitMiddleware({ debug, middlewareAuth, }?: AuthkitMiddlewareOptions): NextMiddleware;
|
|
3
|
+
export declare function authkitMiddleware({ debug, middlewareAuth, redirectUri, }?: AuthkitMiddlewareOptions): NextMiddleware;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { updateSession } from './session.js';
|
|
2
|
+
export function authkitMiddleware({ debug = false, middlewareAuth = { enabled: false, unauthenticatedPaths: [] }, redirectUri = '', } = {}) {
|
|
3
|
+
return function (request) {
|
|
4
|
+
return updateSession(request, debug, middlewareAuth, redirectUri);
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,MAAM,UAAU,iBAAiB,CAAC,EAChC,KAAK,GAAG,KAAK,EACb,cAAc,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,EAAE,EAAE,EAC7D,WAAW,GAAG,EAAE,MACY,EAAE;IAC9B,OAAO,UAAU,OAAO;QACtB,OAAO,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,WAAW,CAAC,CAAC;IACpE,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Button } from './button.js';
|
|
4
|
+
export function MinMaxButton({ children, minimizedValue }) {
|
|
5
|
+
return (React.createElement(Button, { onClick: () => {
|
|
6
|
+
const root = document.querySelector('[data-workos-impersonation-root]');
|
|
7
|
+
root === null || root === void 0 ? void 0 : root.style.setProperty('--wi-minimized', minimizedValue);
|
|
8
|
+
}, style: { padding: 0, width: '1.714em' } }, children));
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=min-max-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"min-max-button.js","sourceRoot":"","sources":["../../src/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"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { AuthkitMiddlewareAuth, NoUserInfo, Session, UserInfo } from './interfaces.js';
|
|
3
|
+
declare function encryptSession(session: Session): Promise<string>;
|
|
4
|
+
declare function updateSession(request: NextRequest, debug: boolean, middlewareAuth: AuthkitMiddlewareAuth, redirectUri: string): Promise<NextResponse<unknown>>;
|
|
5
|
+
declare function refreshSession(options?: {
|
|
6
|
+
organizationId?: string;
|
|
7
|
+
ensureSignedIn: false;
|
|
8
|
+
}): Promise<UserInfo | NoUserInfo>;
|
|
9
|
+
declare function refreshSession(options: {
|
|
10
|
+
organizationId?: string;
|
|
11
|
+
ensureSignedIn: true;
|
|
12
|
+
}): Promise<UserInfo>;
|
|
13
|
+
declare function withAuth(options?: {
|
|
14
|
+
ensureSignedIn: false;
|
|
15
|
+
}): Promise<UserInfo | NoUserInfo>;
|
|
16
|
+
declare function withAuth(options: {
|
|
17
|
+
ensureSignedIn: true;
|
|
18
|
+
}): Promise<UserInfo>;
|
|
19
|
+
declare function terminateSession(): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the session from the cookie. Meant for use in the middleware, for client side use `withAuth` instead.
|
|
22
|
+
*
|
|
23
|
+
* @returns Session | undefined
|
|
24
|
+
*/
|
|
25
|
+
declare function getSession(response?: NextResponse): Promise<{
|
|
26
|
+
sessionId: string;
|
|
27
|
+
user: import("@workos-inc/node").User;
|
|
28
|
+
organizationId: string | undefined;
|
|
29
|
+
role: string | undefined;
|
|
30
|
+
permissions: string[] | undefined;
|
|
31
|
+
impersonator: import("./interfaces.js").Impersonator | undefined;
|
|
32
|
+
accessToken: string;
|
|
33
|
+
} | undefined>;
|
|
34
|
+
export { encryptSession, withAuth, refreshSession, terminateSession, updateSession, getSession };
|