@cabin-id/nextjs 0.1.7 → 0.2.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/dist/cjs/api/{getUserInfo.js → endpoints/AbstractApi.js} +14 -18
- package/dist/cjs/api/endpoints/AbstractApi.js.map +1 -0
- package/dist/cjs/api/endpoints/UserApi.js +40 -0
- package/dist/cjs/api/endpoints/UserApi.js.map +1 -0
- package/dist/cjs/api/endpoints/index.js +32 -0
- package/dist/cjs/api/endpoints/index.js.map +1 -0
- package/dist/cjs/api/factory.js +60 -0
- package/dist/cjs/api/factory.js.map +1 -0
- package/dist/cjs/api/request.js +97 -0
- package/dist/cjs/api/request.js.map +1 -0
- package/dist/cjs/component.client.js +2 -2
- package/dist/cjs/component.client.js.map +1 -1
- package/dist/cjs/component.server.js +5 -2
- package/dist/cjs/component.server.js.map +1 -1
- package/dist/cjs/components/SignInButton.js +15 -6
- package/dist/cjs/components/SignInButton.js.map +1 -1
- package/dist/cjs/constants.js +20 -19
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/hooks/createContextAndHook.js +62 -0
- package/dist/cjs/hooks/createContextAndHook.js.map +1 -0
- package/dist/cjs/hooks/useSafeLayoutEffect.js +40 -0
- package/dist/cjs/hooks/useSafeLayoutEffect.js.map +1 -0
- package/dist/cjs/hooks/useUser.js +9 -16
- package/dist/cjs/hooks/useUser.js.map +1 -1
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/provider/context.js +62 -0
- package/dist/cjs/provider/context.js.map +1 -0
- package/dist/cjs/provider/core.provider.js +49 -0
- package/dist/cjs/provider/core.provider.js.map +1 -0
- package/dist/cjs/{client/provider.js → provider/main.provider.js} +9 -21
- package/dist/cjs/provider/main.provider.js.map +1 -0
- package/dist/cjs/server/auth.js +31 -7
- package/dist/cjs/server/auth.js.map +1 -1
- package/dist/cjs/{client/request.js → server/client.js} +12 -20
- package/dist/cjs/server/client.js.map +1 -0
- package/dist/cjs/server/createGetAuth.js +45 -0
- package/dist/cjs/server/createGetAuth.js.map +1 -0
- package/dist/cjs/server/createRedirect.js +36 -35
- package/dist/cjs/server/createRedirect.js.map +1 -1
- package/dist/cjs/server/errors.js +110 -0
- package/dist/cjs/server/errors.js.map +1 -0
- package/dist/cjs/server/getCurrentUser.js +3 -10
- package/dist/cjs/server/getCurrentUser.js.map +1 -1
- package/dist/cjs/server/index.js +32 -0
- package/dist/cjs/server/index.js.map +1 -0
- package/dist/cjs/server/middleware.js +122 -102
- package/dist/cjs/server/middleware.js.map +1 -1
- package/dist/cjs/server/protect.js +69 -0
- package/dist/cjs/server/protect.js.map +1 -0
- package/dist/cjs/server/routeMatcher.js +1 -0
- package/dist/cjs/server/routeMatcher.js.map +1 -1
- package/dist/cjs/server/serverRedirectWithAuth.js +2 -2
- package/dist/cjs/server/serverRedirectWithAuth.js.map +1 -1
- package/dist/cjs/server/type.js.map +1 -1
- package/dist/cjs/server/utils.js +58 -0
- package/dist/cjs/server/utils.js.map +1 -1
- package/dist/cjs/styles/global.css +30 -2
- package/dist/cjs/styles/global.css.map +1 -1
- package/dist/cjs/tokens/authObjects.js +45 -0
- package/dist/cjs/tokens/authObjects.js.map +1 -0
- package/dist/cjs/tokens/authStatus.js +86 -0
- package/dist/cjs/tokens/authStatus.js.map +1 -0
- package/dist/cjs/tokens/authenticateContext.js +69 -0
- package/dist/cjs/tokens/authenticateContext.js.map +1 -0
- package/dist/cjs/tokens/cabinIdRequest.js +79 -0
- package/dist/cjs/tokens/cabinIdRequest.js.map +1 -0
- package/dist/cjs/tokens/cabinIdUrl.js +36 -0
- package/dist/cjs/tokens/cabinIdUrl.js.map +1 -0
- package/dist/cjs/tokens/request.js +58 -0
- package/dist/cjs/tokens/request.js.map +1 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/createCabinIdClient.js +38 -0
- package/dist/cjs/utils/createCabinIdClient.js.map +1 -0
- package/dist/cjs/utils/http.js +31 -0
- package/dist/cjs/utils/http.js.map +1 -0
- package/dist/cjs/utils/initial.js +51 -0
- package/dist/cjs/utils/initial.js.map +1 -0
- package/dist/cjs/utils.js +10 -0
- package/dist/cjs/utils.js.map +1 -1
- package/dist/esm/api/endpoints/AbstractApi.js +14 -0
- package/dist/esm/api/endpoints/AbstractApi.js.map +1 -0
- package/dist/esm/api/endpoints/UserApi.js +16 -0
- package/dist/esm/api/endpoints/UserApi.js.map +1 -0
- package/dist/esm/api/endpoints/index.js +7 -0
- package/dist/esm/api/endpoints/index.js.map +1 -0
- package/dist/esm/api/factory.js +35 -0
- package/dist/esm/api/factory.js.map +1 -0
- package/dist/esm/api/request.js +63 -0
- package/dist/esm/api/request.js.map +1 -0
- package/dist/esm/component.client.js +1 -1
- package/dist/esm/component.client.js.map +1 -1
- package/dist/esm/component.server.js +3 -1
- package/dist/esm/component.server.js.map +1 -1
- package/dist/esm/components/SignInButton.js +17 -8
- package/dist/esm/components/SignInButton.js.map +1 -1
- package/dist/esm/constants.js +16 -15
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/hooks/createContextAndHook.js +27 -0
- package/dist/esm/hooks/createContextAndHook.js.map +1 -0
- package/dist/esm/hooks/useSafeLayoutEffect.js +6 -0
- package/dist/esm/hooks/useSafeLayoutEffect.js.map +1 -0
- package/dist/esm/hooks/useUser.js +12 -6
- package/dist/esm/hooks/useUser.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/provider/context.js +24 -0
- package/dist/esm/provider/context.js.map +1 -0
- package/dist/esm/provider/core.provider.js +15 -0
- package/dist/esm/provider/core.provider.js.map +1 -0
- package/dist/esm/provider/main.provider.js +11 -0
- package/dist/esm/provider/main.provider.js.map +1 -0
- package/dist/esm/server/auth.js +32 -8
- package/dist/esm/server/auth.js.map +1 -1
- package/dist/esm/server/client.js +11 -0
- package/dist/esm/server/client.js.map +1 -0
- package/dist/esm/server/createGetAuth.js +23 -0
- package/dist/esm/server/createGetAuth.js.map +1 -0
- package/dist/esm/server/createRedirect.js +36 -35
- package/dist/esm/server/createRedirect.js.map +1 -1
- package/dist/esm/server/errors.js +78 -0
- package/dist/esm/server/errors.js.map +1 -0
- package/dist/esm/server/getCurrentUser.js +3 -10
- package/dist/esm/server/getCurrentUser.js.map +1 -1
- package/dist/esm/server/index.js +7 -0
- package/dist/esm/server/index.js.map +1 -0
- package/dist/esm/server/middleware.js +125 -106
- package/dist/esm/server/middleware.js.map +1 -1
- package/dist/esm/server/protect.js +45 -0
- package/dist/esm/server/protect.js.map +1 -0
- package/dist/esm/server/routeMatcher.js +1 -0
- package/dist/esm/server/routeMatcher.js.map +1 -1
- package/dist/esm/server/serverRedirectWithAuth.js +2 -2
- package/dist/esm/server/serverRedirectWithAuth.js.map +1 -1
- package/dist/esm/server/utils.js +54 -1
- package/dist/esm/server/utils.js.map +1 -1
- package/dist/esm/styles/global.css +30 -2
- package/dist/esm/styles/global.css.map +1 -1
- package/dist/esm/tokens/authObjects.js +20 -0
- package/dist/esm/tokens/authObjects.js.map +1 -0
- package/dist/esm/tokens/authStatus.js +59 -0
- package/dist/esm/tokens/authStatus.js.map +1 -0
- package/dist/esm/tokens/authenticateContext.js +45 -0
- package/dist/esm/tokens/authenticateContext.js.map +1 -0
- package/dist/esm/tokens/cabinIdRequest.js +55 -0
- package/dist/esm/tokens/cabinIdRequest.js.map +1 -0
- package/dist/esm/tokens/cabinIdUrl.js +12 -0
- package/dist/esm/tokens/cabinIdUrl.js.map +1 -0
- package/dist/esm/tokens/request.js +34 -0
- package/dist/esm/tokens/request.js.map +1 -0
- package/dist/esm/utils/createCabinIdClient.js +17 -0
- package/dist/esm/utils/createCabinIdClient.js.map +1 -0
- package/dist/esm/utils/http.js +7 -0
- package/dist/esm/utils/http.js.map +1 -0
- package/dist/esm/utils/initial.js +26 -0
- package/dist/esm/utils/initial.js.map +1 -0
- package/dist/esm/utils.js +9 -0
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/api/endpoints/AbstractApi.d.ts +7 -0
- package/dist/types/api/endpoints/AbstractApi.d.ts.map +1 -0
- package/dist/types/api/endpoints/UserApi.d.ts +6 -0
- package/dist/types/api/endpoints/UserApi.d.ts.map +1 -0
- package/dist/types/api/endpoints/index.d.ts +3 -0
- package/dist/types/api/endpoints/index.d.ts.map +1 -0
- package/dist/types/api/factory.d.ts +35 -0
- package/dist/types/api/factory.d.ts.map +1 -0
- package/dist/types/api/request.d.ts +33 -0
- package/dist/types/api/request.d.ts.map +1 -0
- package/dist/types/component.client.d.ts +1 -1
- package/dist/types/component.client.d.ts.map +1 -1
- package/dist/types/component.server.d.ts +1 -0
- package/dist/types/component.server.d.ts.map +1 -1
- package/dist/types/components/SignInButton.d.ts.map +1 -1
- package/dist/types/constants.d.ts +11 -10
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/hooks/createContextAndHook.d.ts +18 -0
- package/dist/types/hooks/createContextAndHook.d.ts.map +1 -0
- package/dist/types/hooks/useSafeLayoutEffect.d.ts +3 -0
- package/dist/types/hooks/useSafeLayoutEffect.d.ts.map +1 -0
- package/dist/types/hooks/useUser.d.ts +16 -1
- package/dist/types/hooks/useUser.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/provider/context.d.ts +15 -0
- package/dist/types/provider/context.d.ts.map +1 -0
- package/dist/types/provider/core.provider.d.ts +6 -0
- package/dist/types/provider/core.provider.d.ts.map +1 -0
- package/dist/types/provider/main.provider.d.ts +5 -0
- package/dist/types/provider/main.provider.d.ts.map +1 -0
- package/dist/types/server/auth.d.ts +10 -3
- package/dist/types/server/auth.d.ts.map +1 -1
- package/dist/types/server/client.d.ts +3 -0
- package/dist/types/server/client.d.ts.map +1 -0
- package/dist/types/server/createGetAuth.d.ts +5 -0
- package/dist/types/server/createGetAuth.d.ts.map +1 -0
- package/dist/types/server/createRedirect.d.ts.map +1 -1
- package/dist/types/server/errors.d.ts +10 -0
- package/dist/types/server/errors.d.ts.map +1 -0
- package/dist/types/server/getCurrentUser.d.ts.map +1 -1
- package/dist/types/server/index.d.ts +3 -0
- package/dist/types/server/index.d.ts.map +1 -0
- package/dist/types/server/middleware.d.ts +22 -77
- package/dist/types/server/middleware.d.ts.map +1 -1
- package/dist/types/server/protect.d.ts +34 -0
- package/dist/types/server/protect.d.ts.map +1 -0
- package/dist/types/server/routeMatcher.d.ts +4 -4
- package/dist/types/server/serverRedirectWithAuth.d.ts +2 -1
- package/dist/types/server/serverRedirectWithAuth.d.ts.map +1 -1
- package/dist/types/server/type.d.ts +10 -1
- package/dist/types/server/type.d.ts.map +1 -1
- package/dist/types/server/utils.d.ts +10 -3
- package/dist/types/server/utils.d.ts.map +1 -1
- package/dist/types/tokens/authObjects.d.ts +37 -0
- package/dist/types/tokens/authObjects.d.ts.map +1 -0
- package/dist/types/tokens/authStatus.d.ts +51 -0
- package/dist/types/tokens/authStatus.d.ts.map +1 -0
- package/dist/types/tokens/authenticateContext.d.ts +40 -0
- package/dist/types/tokens/authenticateContext.d.ts.map +1 -0
- package/dist/types/tokens/cabinIdRequest.d.ts +24 -0
- package/dist/types/tokens/cabinIdRequest.d.ts.map +1 -0
- package/dist/types/tokens/cabinIdUrl.d.ts +18 -0
- package/dist/types/tokens/cabinIdUrl.d.ts.map +1 -0
- package/dist/types/tokens/request.d.ts +4 -0
- package/dist/types/tokens/request.d.ts.map +1 -0
- package/dist/types/types.d.ts +1 -3
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/createCabinIdClient.d.ts +5 -0
- package/dist/types/utils/createCabinIdClient.d.ts.map +1 -0
- package/dist/types/utils/http.d.ts +4 -0
- package/dist/types/utils/http.d.ts.map +1 -0
- package/dist/types/utils/initial.d.ts +8 -0
- package/dist/types/utils/initial.d.ts.map +1 -0
- package/dist/types/utils.d.ts +1 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/package.json +6 -2
- package/server/package.json +5 -0
- package/dist/cjs/api/getUserInfo.js.map +0 -1
- package/dist/cjs/client/provider.js.map +0 -1
- package/dist/cjs/client/request.js.map +0 -1
- package/dist/esm/api/getUserInfo.js +0 -18
- package/dist/esm/api/getUserInfo.js.map +0 -1
- package/dist/esm/client/provider.js +0 -22
- package/dist/esm/client/provider.js.map +0 -1
- package/dist/esm/client/request.js +0 -19
- package/dist/esm/client/request.js.map +0 -1
- package/dist/types/api/getUserInfo.d.ts +0 -2
- package/dist/types/api/getUserInfo.d.ts.map +0 -1
- package/dist/types/client/provider.d.ts +0 -7
- package/dist/types/client/provider.d.ts.map +0 -1
- package/dist/types/client/request.d.ts +0 -3
- package/dist/types/client/request.d.ts.map +0 -1
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var errors_exports = {};
|
|
20
|
+
__export(errors_exports, {
|
|
21
|
+
authAuthHeaderMissing: () => authAuthHeaderMissing,
|
|
22
|
+
authSignatureInvalid: () => authSignatureInvalid,
|
|
23
|
+
clockSkewDetected: () => clockSkewDetected,
|
|
24
|
+
getAuthAuthHeaderMissing: () => getAuthAuthHeaderMissing,
|
|
25
|
+
infiniteRedirectLoopDetected: () => infiniteRedirectLoopDetected,
|
|
26
|
+
informAboutProtectedRouteInfo: () => informAboutProtectedRouteInfo,
|
|
27
|
+
missingDomainAndProxy: () => missingDomainAndProxy,
|
|
28
|
+
missingSignInUrlInDev: () => missingSignInUrlInDev,
|
|
29
|
+
receivedRequestForIgnoredRoute: () => receivedRequestForIgnoredRoute
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(errors_exports);
|
|
32
|
+
const missingDomainAndProxy = `
|
|
33
|
+
Missing domain and proxyUrl. A satellite application needs to specify a domain or a proxyUrl.
|
|
34
|
+
|
|
35
|
+
1) With middleware
|
|
36
|
+
e.g. export default clerkMiddleware({domain:'YOUR_DOMAIN',isSatellite:true}); // or the deprecated authMiddleware()
|
|
37
|
+
2) With environment variables e.g.
|
|
38
|
+
NEXT_PUBLIC_CLERK_DOMAIN='YOUR_DOMAIN'
|
|
39
|
+
NEXT_PUBLIC_CLERK_IS_SATELLITE='true'
|
|
40
|
+
`;
|
|
41
|
+
const missingSignInUrlInDev = `
|
|
42
|
+
Invalid signInUrl. A satellite application requires a signInUrl for development instances.
|
|
43
|
+
Check if signInUrl is missing from your configuration or if it is not an absolute URL
|
|
44
|
+
|
|
45
|
+
1) With middleware
|
|
46
|
+
e.g. export default clerkMiddleware({signInUrl:'SOME_URL', isSatellite:true}); // or the deprecated authMiddleware()
|
|
47
|
+
2) With environment variables e.g.
|
|
48
|
+
NEXT_PUBLIC_CLERK_SIGN_IN_URL='SOME_URL'
|
|
49
|
+
NEXT_PUBLIC_CLERK_IS_SATELLITE='true'`;
|
|
50
|
+
const receivedRequestForIgnoredRoute = (url, matcher) => `Clerk: The middleware was skipped for this request URL: ${url}. For performance reasons, it's recommended to your middleware matcher to:
|
|
51
|
+
export const config = {
|
|
52
|
+
matcher: ${matcher},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
Alternatively, you can set your own ignoredRoutes. See https://clerk.com/docs/nextjs/middleware
|
|
56
|
+
(This log only appears in development mode)
|
|
57
|
+
`;
|
|
58
|
+
const getAuthAuthHeaderMissing = () => authAuthHeaderMissing("getAuth");
|
|
59
|
+
const authAuthHeaderMissing = (helperName = "auth") => `CabinID: ${helperName}() was called but CabinID can't detect usage of authMiddleware(). Please ensure the following:
|
|
60
|
+
- clerkMiddleware() authMiddleware is used in your Next.js Middleware.
|
|
61
|
+
- Your Middleware matcher is configured to match this route or page.
|
|
62
|
+
- If you are using the src directory, make sure the Middleware file is inside of it.
|
|
63
|
+
`;
|
|
64
|
+
const clockSkewDetected = (verifyMessage) => `Clerk: Clock skew detected. This usually means that your system clock is inaccurate. Clerk will continuously try to issue new tokens, as the existing ones will be treated as "expired" due to clock skew.
|
|
65
|
+
|
|
66
|
+
To resolve this issue, make sure your system's clock is set to the correct time (e.g. turn off and on automatic time synchronization).
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
${verifyMessage}`;
|
|
71
|
+
const infiniteRedirectLoopDetected = () => `Clerk: Infinite redirect loop detected. That usually means that we were not able to determine the auth state for this request. A list of common causes and solutions follows.
|
|
72
|
+
|
|
73
|
+
Reason 1:
|
|
74
|
+
Your Clerk instance keys are incorrect, or you recently changed keys (Publishable Key, Secret Key).
|
|
75
|
+
How to resolve:
|
|
76
|
+
-> Make sure you're using the correct keys from the Clerk Dashboard. If you changed keys recently, make sure to clear your browser application data and cookies.
|
|
77
|
+
|
|
78
|
+
Reason 2:
|
|
79
|
+
A bug that may have already been fixed in the latest version of Clerk NextJS package.
|
|
80
|
+
How to resolve:
|
|
81
|
+
-> Make sure you are using the latest version of '@clerk/nextjs' and 'next'.
|
|
82
|
+
`;
|
|
83
|
+
const informAboutProtectedRouteInfo = (path, hasPublicRoutes, hasIgnoredRoutes, isApiRoute, defaultIgnoredRoutes) => {
|
|
84
|
+
const infoText = isApiRoute ? `INFO: Clerk: The request to ${path} is being protected (401) because there is no signed-in user, and the path is included in \`apiRoutes\`. To prevent this behavior, choose one of:` : `INFO: Clerk: The request to ${path} is being redirected because there is no signed-in user, and the path is not included in \`ignoredRoutes\` or \`publicRoutes\`. To prevent this behavior, choose one of:`;
|
|
85
|
+
const apiRoutesText = isApiRoute ? `To prevent Clerk authentication from protecting (401) the api route, remove the rule matching "${path}" from the \`apiRoutes\` array passed to authMiddleware` : void 0;
|
|
86
|
+
const publicRoutesText = hasPublicRoutes ? `To make the route accessible to both signed in and signed out users, add "${path}" to the \`publicRoutes\` array passed to authMiddleware` : `To make the route accessible to both signed in and signed out users, pass \`publicRoutes: ["${path}"]\` to authMiddleware`;
|
|
87
|
+
const ignoredRoutes = [...defaultIgnoredRoutes, path].map((r) => `"${r}"`).join(", ");
|
|
88
|
+
const ignoredRoutesText = hasIgnoredRoutes ? `To prevent Clerk authentication from running at all, add "${path}" to the \`ignoredRoutes\` array passed to authMiddleware` : `To prevent Clerk authentication from running at all, pass \`ignoredRoutes: [${ignoredRoutes}]\` to authMiddleware`;
|
|
89
|
+
const afterAuthText = "Pass a custom `afterAuth` to authMiddleware, and replace Clerk's default behavior of redirecting unless a route is included in publicRoutes";
|
|
90
|
+
return `${infoText}
|
|
91
|
+
|
|
92
|
+
${[apiRoutesText, publicRoutesText, ignoredRoutesText, afterAuthText].filter(Boolean).map((text, index) => `${index + 1}. ${text}`).join("\n")}
|
|
93
|
+
|
|
94
|
+
For additional information about middleware, please visit https://clerk.com/docs/nextjs/middleware
|
|
95
|
+
(This log only appears in development mode, or if \`debug: true\` is passed to authMiddleware)`;
|
|
96
|
+
};
|
|
97
|
+
const authSignatureInvalid = `Clerk: Unable to verify request, this usually means the Clerk middleware did not run. Ensure Clerk's middleware is properly integrated and matches the current route. For more information, see: https://clerk.com/docs/nextjs/middleware. (code=auth_signature_invalid)`;
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
authAuthHeaderMissing,
|
|
101
|
+
authSignatureInvalid,
|
|
102
|
+
clockSkewDetected,
|
|
103
|
+
getAuthAuthHeaderMissing,
|
|
104
|
+
infiniteRedirectLoopDetected,
|
|
105
|
+
informAboutProtectedRouteInfo,
|
|
106
|
+
missingDomainAndProxy,
|
|
107
|
+
missingSignInUrlInDev,
|
|
108
|
+
receivedRequestForIgnoredRoute
|
|
109
|
+
});
|
|
110
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/errors.ts"],"sourcesContent":["export const missingDomainAndProxy = `\nMissing domain and proxyUrl. A satellite application needs to specify a domain or a proxyUrl.\n\n1) With middleware\n e.g. export default clerkMiddleware({domain:'YOUR_DOMAIN',isSatellite:true}); // or the deprecated authMiddleware()\n2) With environment variables e.g.\n NEXT_PUBLIC_CLERK_DOMAIN='YOUR_DOMAIN'\n NEXT_PUBLIC_CLERK_IS_SATELLITE='true'\n `;\n\nexport const missingSignInUrlInDev = `\nInvalid signInUrl. A satellite application requires a signInUrl for development instances.\nCheck if signInUrl is missing from your configuration or if it is not an absolute URL\n\n1) With middleware\n e.g. export default clerkMiddleware({signInUrl:'SOME_URL', isSatellite:true}); // or the deprecated authMiddleware()\n2) With environment variables e.g.\n NEXT_PUBLIC_CLERK_SIGN_IN_URL='SOME_URL'\n NEXT_PUBLIC_CLERK_IS_SATELLITE='true'`;\n\nexport const receivedRequestForIgnoredRoute = (url: string, matcher: string) =>\n `Clerk: The middleware was skipped for this request URL: ${url}. For performance reasons, it's recommended to your middleware matcher to:\nexport const config = {\n matcher: ${matcher},\n};\n\nAlternatively, you can set your own ignoredRoutes. See https://clerk.com/docs/nextjs/middleware\n(This log only appears in development mode)\n`;\n\nexport const getAuthAuthHeaderMissing = () => authAuthHeaderMissing('getAuth');\n\nexport const authAuthHeaderMissing = (helperName = 'auth') =>\n `CabinID: ${helperName}() was called but CabinID can't detect usage of authMiddleware(). Please ensure the following:\n- clerkMiddleware() authMiddleware is used in your Next.js Middleware.\n- Your Middleware matcher is configured to match this route or page.\n- If you are using the src directory, make sure the Middleware file is inside of it.\n`;\n\nexport const clockSkewDetected = (verifyMessage: string) =>\n `Clerk: Clock skew detected. This usually means that your system clock is inaccurate. Clerk will continuously try to issue new tokens, as the existing ones will be treated as \"expired\" due to clock skew.\n\nTo resolve this issue, make sure your system's clock is set to the correct time (e.g. turn off and on automatic time synchronization).\n\n---\n\n${verifyMessage}`;\n\nexport const infiniteRedirectLoopDetected = () =>\n `Clerk: Infinite redirect loop detected. That usually means that we were not able to determine the auth state for this request. A list of common causes and solutions follows.\n\nReason 1:\nYour Clerk instance keys are incorrect, or you recently changed keys (Publishable Key, Secret Key).\nHow to resolve:\n-> Make sure you're using the correct keys from the Clerk Dashboard. If you changed keys recently, make sure to clear your browser application data and cookies.\n\nReason 2:\nA bug that may have already been fixed in the latest version of Clerk NextJS package.\nHow to resolve:\n-> Make sure you are using the latest version of '@clerk/nextjs' and 'next'.\n`;\n\nexport const informAboutProtectedRouteInfo = (\n path: string,\n hasPublicRoutes: boolean,\n hasIgnoredRoutes: boolean,\n isApiRoute: boolean,\n defaultIgnoredRoutes: string[]\n) => {\n const infoText = isApiRoute\n ? `INFO: Clerk: The request to ${path} is being protected (401) because there is no signed-in user, and the path is included in \\`apiRoutes\\`. To prevent this behavior, choose one of:`\n : `INFO: Clerk: The request to ${path} is being redirected because there is no signed-in user, and the path is not included in \\`ignoredRoutes\\` or \\`publicRoutes\\`. To prevent this behavior, choose one of:`;\n const apiRoutesText = isApiRoute\n ? `To prevent Clerk authentication from protecting (401) the api route, remove the rule matching \"${path}\" from the \\`apiRoutes\\` array passed to authMiddleware`\n : undefined;\n const publicRoutesText = hasPublicRoutes\n ? `To make the route accessible to both signed in and signed out users, add \"${path}\" to the \\`publicRoutes\\` array passed to authMiddleware`\n : `To make the route accessible to both signed in and signed out users, pass \\`publicRoutes: [\"${path}\"]\\` to authMiddleware`;\n const ignoredRoutes = [...defaultIgnoredRoutes, path]\n .map((r) => `\"${r}\"`)\n .join(', ');\n const ignoredRoutesText = hasIgnoredRoutes\n ? `To prevent Clerk authentication from running at all, add \"${path}\" to the \\`ignoredRoutes\\` array passed to authMiddleware`\n : `To prevent Clerk authentication from running at all, pass \\`ignoredRoutes: [${ignoredRoutes}]\\` to authMiddleware`;\n const afterAuthText =\n \"Pass a custom `afterAuth` to authMiddleware, and replace Clerk's default behavior of redirecting unless a route is included in publicRoutes\";\n\n return `${infoText}\n\n${[apiRoutesText, publicRoutesText, ignoredRoutesText, afterAuthText]\n .filter(Boolean)\n .map((text, index) => `${index + 1}. ${text}`)\n .join('\\n')}\n\nFor additional information about middleware, please visit https://clerk.com/docs/nextjs/middleware\n(This log only appears in development mode, or if \\`debug: true\\` is passed to authMiddleware)`;\n};\n\nexport const authSignatureInvalid = `Clerk: Unable to verify request, this usually means the Clerk middleware did not run. Ensure Clerk's middleware is properly integrated and matches the current route. For more information, see: https://clerk.com/docs/nextjs/middleware. (code=auth_signature_invalid)`;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,wBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAU9B,MAAM,wBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAU9B,MAAM,iCAAiC,CAAC,KAAa,YAC1D,2DAA2D,GAAG;AAAA;AAAA,aAEnD,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAOb,MAAM,2BAA2B,MAAM,sBAAsB,SAAS;AAEtE,MAAM,wBAAwB,CAAC,aAAa,WACjD,YAAY,UAAU;AAAA;AAAA;AAAA;AAAA;AAMjB,MAAM,oBAAoB,CAAC,kBAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,aAAa;AAER,MAAM,+BAA+B,MAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaK,MAAM,gCAAgC,CAC3C,MACA,iBACA,kBACA,YACA,yBACG;AACH,QAAM,WAAW,aACb,+BAA+B,IAAI,sJACnC,+BAA+B,IAAI;AACvC,QAAM,gBAAgB,aAClB,kGAAkG,IAAI,4DACtG;AACJ,QAAM,mBAAmB,kBACrB,6EAA6E,IAAI,6DACjF,+FAA+F,IAAI;AACvG,QAAM,gBAAgB,CAAC,GAAG,sBAAsB,IAAI,EACjD,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,EACnB,KAAK,IAAI;AACZ,QAAM,oBAAoB,mBACtB,6DAA6D,IAAI,8DACjE,+EAA+E,aAAa;AAChG,QAAM,gBACJ;AAEF,SAAO,GAAG,QAAQ;AAAA;AAAA,EAElB,CAAC,eAAe,kBAAkB,mBAAmB,aAAa,EACjE,OAAO,OAAO,EACd,IAAI,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,IAAI,EAAE,EAC5C,KAAK,IAAI,CAAC;AAAA;AAAA;AAAA;AAIb;AAEO,MAAM,uBAAuB;","names":[]}
|
|
@@ -21,20 +21,13 @@ __export(getCurrentUser_exports, {
|
|
|
21
21
|
currentUser: () => currentUser
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(getCurrentUser_exports);
|
|
24
|
-
var import_constants = require("../constants");
|
|
25
24
|
var import_auth = require("./auth");
|
|
25
|
+
var import_http = require("../utils/http");
|
|
26
26
|
async function currentUser() {
|
|
27
|
-
const { userId } =
|
|
27
|
+
const { userId } = (0, import_auth.auth)();
|
|
28
28
|
if (!userId)
|
|
29
29
|
return null;
|
|
30
|
-
|
|
31
|
-
method: "GET",
|
|
32
|
-
headers: {
|
|
33
|
-
Authorization: `Bearer ${import_constants.SECRET_KEY}`
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
const data = await response.json();
|
|
37
|
-
return data;
|
|
30
|
+
return import_http.client.users.getUser(userId);
|
|
38
31
|
}
|
|
39
32
|
// Annotate the CommonJS export names for ESM import in node:
|
|
40
33
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/getCurrentUser.ts"],"sourcesContent":["import { User } from '../types';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/server/getCurrentUser.ts"],"sourcesContent":["import { User } from '../types';\nimport { auth } from './auth';\nimport { client } from '../utils/http';\n\nexport async function currentUser(): Promise<User | null> {\n const { userId } = auth();\n if (!userId) return null;\n return client.users.getUser(userId);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAqB;AACrB,kBAAuB;AAEvB,eAAsB,cAAoC;AACxD,QAAM,EAAE,OAAO,QAAI,kBAAK;AACxB,MAAI,CAAC;AAAQ,WAAO;AACpB,SAAO,mBAAO,MAAM,QAAQ,MAAM;AACpC;","names":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var server_exports = {};
|
|
20
|
+
__export(server_exports, {
|
|
21
|
+
auth: () => import_auth.auth,
|
|
22
|
+
createRouteMatcher: () => import_routeMatcher.createRouteMatcher
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(server_exports);
|
|
25
|
+
var import_auth = require("./auth");
|
|
26
|
+
var import_routeMatcher = require("./routeMatcher");
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
auth,
|
|
30
|
+
createRouteMatcher
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export { auth } from './auth';\nexport { createRouteMatcher } from './routeMatcher';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqB;AACrB,0BAAmC;","names":[]}
|
|
@@ -18,27 +18,38 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var middleware_exports = {};
|
|
20
20
|
__export(middleware_exports, {
|
|
21
|
-
|
|
22
|
-
DEFAULT_CONFIG_MATCHER: () => DEFAULT_CONFIG_MATCHER,
|
|
23
|
-
DEFAULT_IGNORED_ROUTES: () => DEFAULT_IGNORED_ROUTES,
|
|
24
|
-
authMiddleware: () => authMiddleware,
|
|
25
|
-
createDefaultAfterAuth: () => createDefaultAfterAuth
|
|
21
|
+
authMiddleware: () => authMiddleware
|
|
26
22
|
});
|
|
27
23
|
module.exports = __toCommonJS(middleware_exports);
|
|
28
24
|
var import_server = require("next/server");
|
|
29
25
|
var import_constants = require("../constants");
|
|
30
|
-
var import_routeMatcher = require("./routeMatcher");
|
|
31
26
|
var import_utils = require("./utils");
|
|
27
|
+
var import_client = require("./client");
|
|
28
|
+
var import_cabinIdRequest = require("../tokens/cabinIdRequest");
|
|
29
|
+
var import_protect = require("./protect");
|
|
32
30
|
var import_createRedirect = require("./createRedirect");
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
var import_response = require("../utils/response");
|
|
32
|
+
var import_serverRedirectWithAuth = require("./serverRedirectWithAuth");
|
|
33
|
+
const CONTROL_FLOW_ERROR = {
|
|
34
|
+
FORCE_NOT_FOUND: "CABIN_ID_PROTECT_REWRITE",
|
|
35
|
+
REDIRECT_TO_URL: "CABIN_ID_PROTECT_REDIRECT_TO_URL",
|
|
36
|
+
REDIRECT_TO_SIGN_IN: "CABIN_ID_PROTECT_REDIRECT_TO_SIGN_IN"
|
|
37
|
+
};
|
|
38
|
+
const parseRequestAndEvent = (args) => {
|
|
39
|
+
return [
|
|
40
|
+
args[0] instanceof Request ? args[0] : void 0,
|
|
41
|
+
args[0] instanceof Request ? args[1] : void 0
|
|
42
|
+
];
|
|
43
|
+
};
|
|
44
|
+
const parseHandlerAndOptions = (args) => {
|
|
45
|
+
return [
|
|
46
|
+
typeof args[0] === "function" ? args[0] : void 0,
|
|
47
|
+
(args.length === 2 ? args[1] : typeof args[0] === "function" ? {} : args[0]) || {}
|
|
48
|
+
];
|
|
49
|
+
};
|
|
40
50
|
const authMiddleware = (...args) => {
|
|
41
|
-
const [
|
|
51
|
+
const [request, event] = parseRequestAndEvent(args);
|
|
52
|
+
const [handler, params] = parseHandlerAndOptions(args);
|
|
42
53
|
const publishableKey = (0, import_utils.assertKey)(
|
|
43
54
|
params.publishableKey || import_constants.PUBLISHABLE_KEY,
|
|
44
55
|
() => {
|
|
@@ -48,8 +59,8 @@ const authMiddleware = (...args) => {
|
|
|
48
59
|
const secretKey = (0, import_utils.assertKey)(params.secretKey || import_constants.SECRET_KEY, () => {
|
|
49
60
|
throw new Error("Secret Key is not valid");
|
|
50
61
|
});
|
|
51
|
-
const signInUrl = params.signInUrl || import_constants.
|
|
52
|
-
const signUpUrl = params.signUpUrl || import_constants.
|
|
62
|
+
const signInUrl = params.signInUrl || import_constants.SIGN_IN_URL;
|
|
63
|
+
const signUpUrl = params.signUpUrl || import_constants.SIGN_UP_URL;
|
|
53
64
|
const options = {
|
|
54
65
|
...params,
|
|
55
66
|
publishableKey,
|
|
@@ -57,109 +68,118 @@ const authMiddleware = (...args) => {
|
|
|
57
68
|
signInUrl,
|
|
58
69
|
signUpUrl
|
|
59
70
|
};
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const url = _req.nextUrl;
|
|
68
|
-
const accessToken = url.searchParams.get(import_constants.constants.QueryParams.Token);
|
|
69
|
-
const userId = url.searchParams.get(import_constants.constants.QueryParams.UserId);
|
|
71
|
+
const nextMiddleware = async (_request, _event) => {
|
|
72
|
+
const accessToken = _request.nextUrl.searchParams.get(
|
|
73
|
+
import_constants.constants.QueryParams.Token
|
|
74
|
+
);
|
|
75
|
+
const userId = _request.nextUrl.searchParams.get(
|
|
76
|
+
import_constants.constants.QueryParams.UserId
|
|
77
|
+
);
|
|
70
78
|
if (accessToken && userId) {
|
|
79
|
+
const url = _request.nextUrl;
|
|
71
80
|
const path = url.pathname;
|
|
72
|
-
const response = import_server.NextResponse.redirect(
|
|
81
|
+
const response = import_server.NextResponse.redirect(
|
|
82
|
+
new URL(path || "/", _request.url)
|
|
83
|
+
);
|
|
73
84
|
response.cookies.set(import_constants.constants.Cookies.Client, accessToken);
|
|
74
85
|
response.cookies.set(import_constants.constants.Cookies.User, userId);
|
|
75
86
|
return response;
|
|
76
87
|
}
|
|
77
|
-
|
|
78
|
-
|
|
88
|
+
const cabinIdRequest = (0, import_cabinIdRequest.createCabinIdRequest)(_request);
|
|
89
|
+
const requestState = await import_client.cabinIdClient.authenticateRequest(
|
|
90
|
+
cabinIdRequest,
|
|
91
|
+
options
|
|
92
|
+
);
|
|
93
|
+
const authObject = requestState.toAuth();
|
|
94
|
+
const redirectToSignIn = createMiddlewareRedirectToSignIn(cabinIdRequest);
|
|
95
|
+
const protect = createMiddlewareProtect(
|
|
96
|
+
cabinIdRequest,
|
|
97
|
+
authObject,
|
|
98
|
+
redirectToSignIn
|
|
99
|
+
);
|
|
100
|
+
const authObjWithMethods = Object.assign(
|
|
101
|
+
authObject,
|
|
102
|
+
{ protect, redirectToSignIn }
|
|
103
|
+
);
|
|
104
|
+
let handlerResult = import_server.NextResponse.next();
|
|
105
|
+
try {
|
|
106
|
+
handlerResult = await (handler == null ? void 0 : handler(() => authObjWithMethods, _request, _event)) || handlerResult;
|
|
107
|
+
} catch (e) {
|
|
108
|
+
handlerResult = handleControlFlowErrors(e, cabinIdRequest, requestState);
|
|
109
|
+
}
|
|
110
|
+
if ((0, import_response.isRedirect)(handlerResult)) {
|
|
111
|
+
return (0, import_serverRedirectWithAuth.serverRedirectWithAuth)(cabinIdRequest, handlerResult);
|
|
79
112
|
}
|
|
80
|
-
|
|
81
|
-
|
|
113
|
+
(0, import_utils.decorateRequest)(
|
|
114
|
+
cabinIdRequest,
|
|
115
|
+
handlerResult,
|
|
116
|
+
requestState,
|
|
117
|
+
options.secretKey
|
|
118
|
+
);
|
|
119
|
+
if (requestState.headers) {
|
|
120
|
+
requestState.headers.forEach((value, key) => {
|
|
121
|
+
handlerResult.headers.append(key, value);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return handlerResult;
|
|
82
125
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (typeof publicRoutes === "function") {
|
|
86
|
-
return publicRoutes;
|
|
126
|
+
if (request && event) {
|
|
127
|
+
return nextMiddleware(request, event);
|
|
87
128
|
}
|
|
88
|
-
|
|
89
|
-
const signInUrl = process.env.NEXT_PUBLIC_CLERK_SIGN_IN_URL || "";
|
|
90
|
-
if (signInUrl) {
|
|
91
|
-
routes.push(matchRoutesStartingWith(signInUrl));
|
|
92
|
-
}
|
|
93
|
-
const signUpUrl = process.env.NEXT_PUBLIC_CLERK_SIGN_UP_URL || "";
|
|
94
|
-
if (signUpUrl) {
|
|
95
|
-
routes.push(matchRoutesStartingWith(signUpUrl));
|
|
96
|
-
}
|
|
97
|
-
return routes;
|
|
98
|
-
};
|
|
99
|
-
const matchRoutesStartingWith = (path) => {
|
|
100
|
-
path = path.replace(/\/$/, "");
|
|
101
|
-
return new RegExp(`^${path}(/.*)?$`);
|
|
102
|
-
};
|
|
103
|
-
const isRequestMethodIndicatingApiRoute = (req) => {
|
|
104
|
-
const requestMethod = req.method.toLowerCase();
|
|
105
|
-
return !["get", "head", "options"].includes(requestMethod);
|
|
129
|
+
return nextMiddleware;
|
|
106
130
|
};
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return (0, import_routeMatcher.createRouteMatcher)(apiRoutes);
|
|
114
|
-
}
|
|
115
|
-
const isDefaultApiRoute = (0, import_routeMatcher.createRouteMatcher)(DEFAULT_API_ROUTES);
|
|
116
|
-
return (req) => isDefaultApiRoute(req) || isRequestMethodIndicatingApiRoute(req) || isRequestContentTypeJson(req);
|
|
131
|
+
const createMiddlewareRedirectToSignIn = (cabinIdRequest) => {
|
|
132
|
+
return (opts = {}) => {
|
|
133
|
+
const err = new Error(CONTROL_FLOW_ERROR.REDIRECT_TO_SIGN_IN);
|
|
134
|
+
err.returnBackUrl = opts.returnBackUrl === null ? "" : opts.returnBackUrl || cabinIdRequest.cabinIdUrl.toString();
|
|
135
|
+
throw err;
|
|
136
|
+
};
|
|
117
137
|
};
|
|
118
|
-
const
|
|
119
|
-
return (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
138
|
+
const createMiddlewareProtect = (cabinIdRequest, authObject, redirectToSignIn) => {
|
|
139
|
+
return (_, options) => {
|
|
140
|
+
const notFound = () => {
|
|
141
|
+
throw new Error(CONTROL_FLOW_ERROR.FORCE_NOT_FOUND);
|
|
142
|
+
};
|
|
143
|
+
const redirect = (url) => {
|
|
144
|
+
const err = new Error(CONTROL_FLOW_ERROR.REDIRECT_TO_URL);
|
|
145
|
+
err.redirectUrl = url;
|
|
146
|
+
throw err;
|
|
147
|
+
};
|
|
148
|
+
return (0, import_protect.createProtect)({
|
|
149
|
+
request: cabinIdRequest,
|
|
150
|
+
redirect,
|
|
151
|
+
notFound,
|
|
152
|
+
authObject,
|
|
153
|
+
redirectToSignIn
|
|
154
|
+
})(options);
|
|
135
155
|
};
|
|
136
156
|
};
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
});
|
|
147
|
-
return import_server.NextResponse.redirect(
|
|
148
|
-
new URL(`${import_constants.frontendApi}/sign-in?${params.toString()}`)
|
|
157
|
+
const handleControlFlowErrors = (e, cabinIdRequest, requestState) => {
|
|
158
|
+
switch (e.message) {
|
|
159
|
+
case CONTROL_FLOW_ERROR.FORCE_NOT_FOUND:
|
|
160
|
+
return (0, import_response.setHeader)(
|
|
161
|
+
import_server.NextResponse.rewrite(
|
|
162
|
+
`${cabinIdRequest.cabinIdUrl.origin}/cabin_${Date.now()}`
|
|
163
|
+
),
|
|
164
|
+
import_constants.constants.Headers.AuthReason,
|
|
165
|
+
"protect-rewrite"
|
|
149
166
|
);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
167
|
+
case CONTROL_FLOW_ERROR.REDIRECT_TO_URL:
|
|
168
|
+
return (0, import_utils.redirectAdapter)(e.redirectUrl);
|
|
169
|
+
case CONTROL_FLOW_ERROR.REDIRECT_TO_SIGN_IN:
|
|
170
|
+
return (0, import_createRedirect.createRedirect)({
|
|
171
|
+
redirectAdapter: import_utils.redirectAdapter,
|
|
172
|
+
baseUrl: cabinIdRequest.cabinIdUrl,
|
|
173
|
+
signInUrl: requestState.signInUrl,
|
|
174
|
+
signUpUrl: requestState.signUpUrl,
|
|
175
|
+
publishableKey: requestState.publishableKey
|
|
176
|
+
}).redirectToSignIn({ returnBackUrl: e.returnBackUrl });
|
|
177
|
+
default:
|
|
178
|
+
throw e;
|
|
154
179
|
}
|
|
155
|
-
return import_server.NextResponse.next();
|
|
156
180
|
};
|
|
157
181
|
// Annotate the CommonJS export names for ESM import in node:
|
|
158
182
|
0 && (module.exports = {
|
|
159
|
-
|
|
160
|
-
DEFAULT_CONFIG_MATCHER,
|
|
161
|
-
DEFAULT_IGNORED_ROUTES,
|
|
162
|
-
authMiddleware,
|
|
163
|
-
createDefaultAfterAuth
|
|
183
|
+
authMiddleware
|
|
164
184
|
});
|
|
165
185
|
//# sourceMappingURL=middleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/middleware.ts"],"sourcesContent":["import { NextFetchEvent, NextMiddleware, NextResponse } from 'next/server';\nimport { NextRequest } from 'next/server';\nimport {\n constants,\n CUSTOM_AFTER_SIGN_IN_URL,\n CUSTOM_SIGN_IN_URL,\n frontendApi,\n PUBLISHABLE_KEY,\n SECRET_KEY,\n} from '../constants';\nimport { createRouteMatcher, RouteMatcherParam } from './routeMatcher';\nimport {\n apiEndpointUnauthorizedNextResponse,\n assertKey,\n // decorateRequest,\n redirectAdapter,\n} from './utils';\nimport { NextMiddlewareReturn } from './type';\n// import { isRedirect, setHeader } from '../utils/response';\nimport { createRedirect } from './createRedirect';\n// import { serverRedirectWithAuth } from './serverRedirectWithAuth';\n\ntype BeforeAuthHandler = (\n req: NextRequest,\n evt: NextFetchEvent\n) => NextMiddlewareReturn | false | Promise<false>;\n\ntype AfterAuthHandler = (\n auth: { isPublicRoute: boolean; isApiRoute: boolean },\n req: NextRequest,\n evt: NextFetchEvent\n) => NextMiddlewareReturn;\n\nexport type AuthenticateRequestOptions = {\n publishableKey?: string;\n secretKey?: string;\n domain?: string;\n isSatellite?: boolean;\n proxyUrl?: string;\n signInUrl?: string;\n signUpUrl?: string;\n afterSignInUrl?: string;\n afterSignUpUrl?: string;\n};\n\ntype AuthMiddlewareParams = AuthenticateRequestOptions & {\n /**\n * A function that is called before the authentication middleware is executed.\n * If a redirect response is returned, the middleware will respect it and redirect the user.\n * If false is returned, the auth middleware will not execute and the request will be handled as if the auth middleware was not present.\n */\n beforeAuth?: BeforeAuthHandler;\n /**\n * A function that is called after the authentication middleware is executed.\n * This function has access to the auth object and can be used to execute logic based on the auth state.\n */\n afterAuth?: AfterAuthHandler;\n /**\n * A list of routes that should be accessible without authentication.\n * You can use glob patterns to match multiple routes or a function to match against the request object.\n * Path patterns and regular expressions are supported, for example: `['/foo', '/bar(.*)'] or `[/^\\/foo\\/.*$/]`\n * The sign in and sign up URLs are included by default, unless a function is provided.\n * For more information, see: https://clerk.com/docs\n */\n publicRoutes?: RouteMatcherParam;\n /**\n * A list of routes that should be ignored by the middleware.\n * This list typically includes routes for static files or Next.js internals.\n * For improved performance, these routes should be skipped using the default config.matcher instead.\n */\n ignoredRoutes?: IgnoredRoutesParam;\n /**\n * A list of routes that should be treated as API endpoints.\n * When user is signed out, the middleware will return a 401 response for these routes, instead of redirecting the user.\n *\n * If omitted, the following heuristics will be used to determine an API endpoint:\n * - The route path is ['/api/(.*)', '/trpc/(.*)'],\n * - or the request has `Content-Type` set to `application/json`,\n * - or the request method is not one of: `GET`, `OPTIONS` ,` HEAD`\n *\n * @default undefined\n */\n apiRoutes?: ApiRoutesParam;\n};\n\nexport interface AuthMiddleware {\n (params?: AuthMiddlewareParams): NextMiddleware;\n}\n\n/**\n * The default ideal matcher that excludes the _next directory (internals) and all static files,\n * but it will match the root route (/) and any routes that start with /api or /trpc.\n */\nexport const DEFAULT_CONFIG_MATCHER = [\n '/((?!.+\\\\.[\\\\w]+$|_next).*)',\n '/',\n '/(api|trpc)(.*)',\n];\n\n/**\n * Any routes matching this path will be ignored by the middleware.\n * This is the inverted version of DEFAULT_CONFIG_MATCHER.\n */\nexport const DEFAULT_IGNORED_ROUTES = [`/((?!api|trpc))(_next.*|.+\\\\.[\\\\w]+$)`];\n/**\n * Any routes matching this path will be treated as API endpoints by the middleware.\n */\nexport const DEFAULT_API_ROUTES = ['/api/(.*)', '/trpc/(.*)'];\n\ntype IgnoredRoutesParam =\n | Array<RegExp | string>\n | RegExp\n | string\n | ((req: NextRequest) => boolean);\n\ntype ApiRoutesParam = IgnoredRoutesParam;\n\nconst authMiddleware: AuthMiddleware = (...args: unknown[]) => {\n const [params = {}] = args as [AuthMiddlewareParams?];\n\n const publishableKey = assertKey(\n params.publishableKey || PUBLISHABLE_KEY,\n () => {\n throw new Error('Publish Key is not exist');\n }\n );\n const secretKey = assertKey(params.secretKey || SECRET_KEY, () => {\n throw new Error('Secret Key is not valid');\n });\n\n const signInUrl = params.signInUrl || CUSTOM_SIGN_IN_URL;\n const signUpUrl = params.signUpUrl || CUSTOM_SIGN_IN_URL;\n\n const options = {\n ...params,\n publishableKey,\n secretKey,\n signInUrl,\n signUpUrl,\n };\n\n const isIgnoredRoute = createRouteMatcher(\n options.ignoredRoutes || DEFAULT_IGNORED_ROUTES\n );\n const isPublicRoute = createRouteMatcher(\n withDefaultPublicRoutes(options.publicRoutes)\n );\n // const isApiRoute = createApiRoutes(options.apiRoutes);\n // const defaultAfterAuth = createDefaultAfterAuth(\n // isPublicRoute,\n // isApiRoute,\n // options\n // );\n\n return async (_req: NextRequest) => {\n const url = _req.nextUrl;\n\n const accessToken = url.searchParams.get(constants.QueryParams.Token);\n const userId = url.searchParams.get(constants.QueryParams.UserId);\n\n if (accessToken && userId) {\n const path = url.pathname;\n const response = NextResponse.redirect(new URL(path || '/', _req.url));\n response.cookies.set(constants.Cookies.Client, accessToken);\n response.cookies.set(constants.Cookies.User, userId);\n return response;\n }\n\n if (isIgnoredRoute(_req) || isPublicRoute(_req)) {\n return;\n }\n // const nextRequest = _req;\n\n // const beforeAuthRes = await (options.beforeAuth &&\n // options.beforeAuth(nextRequest, evt));\n\n // if (beforeAuthRes === false) {\n // return setHeader(\n // NextResponse.next(),\n // constants.Headers.AuthReason,\n // 'skip'\n // );\n // } else if (beforeAuthRes && isRedirect(beforeAuthRes)) {\n // return setHeader(\n // beforeAuthRes,\n // constants.Headers.AuthReason,\n // 'before-auth-redirect'\n // );\n // }\n\n // const requestState = {\n // token: accessToken,\n // userId,\n // };\n\n // const auth = {\n // ...requestState,\n // isPublicRoute: isPublicRoute(nextRequest),\n // isApiRoute: isApiRoute(nextRequest),\n // };\n\n // const afterAuthRes = await (options.afterAuth || defaultAfterAuth)(\n // auth,\n // nextRequest,\n // evt\n // );\n\n // const finalRes =\n // mergeResponses(beforeAuthRes, afterAuthRes) || NextResponse.next();\n\n // console.log(finalRes);\n\n // if (isRedirect(finalRes)) {\n // const res = serverRedirectWithAuth(finalRes);\n // return res;\n // }\n\n const result = checkAuth(_req);\n\n return result;\n };\n};\n\nconst withDefaultPublicRoutes = (\n publicRoutes: RouteMatcherParam | undefined\n) => {\n if (typeof publicRoutes === 'function') {\n return publicRoutes;\n }\n\n const routes = [publicRoutes || ''].flat().filter(Boolean);\n // TODO: refactor it to use common config file eg SIGN_IN_URL from ./clerkClient\n // we use process.env for now to support testing\n const signInUrl = process.env.NEXT_PUBLIC_CLERK_SIGN_IN_URL || '';\n if (signInUrl) {\n routes.push(matchRoutesStartingWith(signInUrl));\n }\n // TODO: refactor it to use common config file eg SIGN_UP_URL from ./clerkClient\n // we use process.env for now to support testing\n const signUpUrl = process.env.NEXT_PUBLIC_CLERK_SIGN_UP_URL || '';\n if (signUpUrl) {\n routes.push(matchRoutesStartingWith(signUpUrl));\n }\n return routes;\n};\n\nconst matchRoutesStartingWith = (path: string) => {\n path = path.replace(/\\/$/, '');\n return new RegExp(`^${path}(/.*)?$`);\n};\n\nconst isRequestMethodIndicatingApiRoute = (req: NextRequest): boolean => {\n const requestMethod = req.method.toLowerCase();\n return !['get', 'head', 'options'].includes(requestMethod);\n};\n\nconst isRequestContentTypeJson = (req: NextRequest): boolean => {\n const requestContentType = req.headers.get(constants.Headers.ContentType);\n return requestContentType === constants.ContentTypes.Json;\n};\n\n// - Default behavior:\n// If the route path is `['/api/(.*)*', '*/trpc/(.*)']`\n// or Request has `Content-Type: application/json`\n// or Request method is not-GET,OPTIONS,HEAD,\n// then this is considered an API route.\n//\n// - If the user has provided a specific `apiRoutes` prop in `authMiddleware` then all the above are discarded,\n// and only routes that match the user’s provided paths are considered API routes.\nconst createApiRoutes = (\n apiRoutes: RouteMatcherParam | undefined\n): ((req: NextRequest) => boolean) => {\n if (apiRoutes) {\n return createRouteMatcher(apiRoutes);\n }\n const isDefaultApiRoute = createRouteMatcher(DEFAULT_API_ROUTES);\n return (req: NextRequest) =>\n isDefaultApiRoute(req) ||\n isRequestMethodIndicatingApiRoute(req) ||\n isRequestContentTypeJson(req);\n};\n\nexport const createDefaultAfterAuth = (\n isPublicRoute: ReturnType<typeof createRouteMatcher>,\n isApiRoute: ReturnType<typeof createApiRoutes>,\n options: {\n signInUrl: string;\n signUpUrl: string;\n publishableKey: string;\n secretKey: string;\n }\n) => {\n return (auth: any, req: NextRequest) => {\n if (!auth.userId && !isPublicRoute(req)) {\n if (isApiRoute(req)) {\n return apiEndpointUnauthorizedNextResponse();\n }\n return createRedirect({\n redirectAdapter,\n signInUrl: options.signInUrl,\n signUpUrl: options.signUpUrl,\n publishableKey: options.publishableKey,\n // We're setting baseUrl to '' here as we want to keep the legacy behavior of\n // the redirectToSignIn, redirectToSignUp helpers in the backend package.\n baseUrl: '',\n }).redirectToSignIn({ returnBackUrl: req.nextUrl.href });\n }\n return NextResponse.next();\n };\n};\n\nconst checkAuth = (req: NextRequest): any => {\n const accessToken = req.cookies.get(constants.Cookies.Client);\n\n if (!accessToken && req.nextUrl.href !== CUSTOM_SIGN_IN_URL) {\n if (CUSTOM_SIGN_IN_URL) {\n return NextResponse.redirect(new URL(CUSTOM_SIGN_IN_URL));\n }\n\n if (frontendApi) {\n const params = new URLSearchParams({\n redirect_url: CUSTOM_AFTER_SIGN_IN_URL || '/',\n });\n return NextResponse.redirect(\n new URL(`${frontendApi}/sign-in?${params.toString()}`)\n );\n }\n throw new Error(\n 'You are not authentication. Please provide CABIN ID PUBLISH KEY to redirect to authentication page'\n );\n }\n return NextResponse.next();\n};\n\nexport { authMiddleware };\n"],"mappings":"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","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/server/middleware.ts"],"sourcesContent":["import { NextMiddleware, NextResponse } from 'next/server';\nimport {\n constants,\n PUBLISHABLE_KEY,\n SECRET_KEY,\n SIGN_IN_URL,\n SIGN_UP_URL,\n} from '../constants';\nimport { assertKey, decorateRequest, redirectAdapter } from './utils';\nimport {\n NextMiddlewareEvtParam,\n NextMiddlewareRequestParam,\n NextMiddlewareReturn,\n} from './type';\nimport { cabinIdClient } from './client';\nimport { CabinIdRequest, createCabinIdRequest } from '../tokens/cabinIdRequest';\nimport { AuthProtect, createProtect } from './protect';\nimport { createRedirect, RedirectFun } from './createRedirect';\nimport { isRedirect, setHeader } from '../utils/response';\nimport { RequestState } from '../tokens/authStatus';\nimport { AuthObject } from '../tokens/authObjects';\nimport { serverRedirectWithAuth } from './serverRedirectWithAuth';\nimport { AuthenticateRequestOptions } from '../api/factory';\n\nconst CONTROL_FLOW_ERROR = {\n FORCE_NOT_FOUND: 'CABIN_ID_PROTECT_REWRITE',\n REDIRECT_TO_URL: 'CABIN_ID_PROTECT_REDIRECT_TO_URL',\n REDIRECT_TO_SIGN_IN: 'CABIN_ID_PROTECT_REDIRECT_TO_SIGN_IN',\n};\n\nexport type CabinIdMiddlewareAuthObject = AuthObject & {\n protect: AuthProtect;\n redirectToSignIn: RedirectFun<Response>;\n};\n\nexport type CabinIdMiddlewareAuth = () => CabinIdMiddlewareAuthObject;\n\nexport interface AuthMiddleware {\n /**\n * @example\n * export default clerkMiddleware((auth, request, event) => { ... }, options);\n */\n (\n handler: CabinIdMiddlewareHandler,\n options?: CabinIdMiddlewareOptions\n ): NextMiddleware;\n /**\n * @example\n * export default clerkMiddleware(options);\n */\n (options?: CabinIdMiddlewareOptions): NextMiddleware;\n /**\n * @example\n * export default clerkMiddleware;\n */\n (\n request: NextMiddlewareRequestParam,\n event: NextMiddlewareEvtParam\n ): NextMiddlewareReturn;\n}\n\ntype CabinIdMiddlewareHandler = (\n auth: CabinIdMiddlewareAuth,\n request: NextMiddlewareRequestParam,\n event: NextMiddlewareEvtParam\n) => NextMiddlewareReturn;\n\nexport type CabinIdMiddlewareOptions = AuthenticateRequestOptions;\n\nconst parseRequestAndEvent = (args: unknown[]) => {\n return [\n args[0] instanceof Request ? args[0] : undefined,\n args[0] instanceof Request ? args[1] : undefined,\n ] as [\n NextMiddlewareRequestParam | undefined,\n NextMiddlewareEvtParam | undefined,\n ];\n};\n\nconst parseHandlerAndOptions = (args: unknown[]) => {\n return [\n typeof args[0] === 'function' ? args[0] : undefined,\n (args.length === 2\n ? args[1]\n : typeof args[0] === 'function'\n ? {}\n : args[0]) || {},\n ] as [CabinIdMiddlewareHandler | undefined, CabinIdMiddlewareOptions];\n};\n\nconst authMiddleware: AuthMiddleware = (...args: unknown[]): any => {\n const [request, event] = parseRequestAndEvent(args);\n const [handler, params] = parseHandlerAndOptions(args);\n\n const publishableKey = assertKey(\n params.publishableKey || PUBLISHABLE_KEY,\n () => {\n throw new Error('Publish Key is not exist');\n }\n );\n const secretKey = assertKey(params.secretKey || SECRET_KEY, () => {\n throw new Error('Secret Key is not valid');\n });\n\n const signInUrl = params.signInUrl || SIGN_IN_URL;\n const signUpUrl = params.signUpUrl || SIGN_UP_URL;\n\n const options = {\n ...params,\n publishableKey,\n secretKey,\n signInUrl,\n signUpUrl,\n };\n\n const nextMiddleware: NextMiddleware = async (_request, _event) => {\n const accessToken = _request.nextUrl.searchParams.get(\n constants.QueryParams.Token\n );\n const userId = _request.nextUrl.searchParams.get(\n constants.QueryParams.UserId\n );\n\n if (accessToken && userId) {\n const url = _request.nextUrl;\n const path = url.pathname;\n const response = NextResponse.redirect(\n new URL(path || '/', _request.url)\n );\n response.cookies.set(constants.Cookies.Client, accessToken);\n response.cookies.set(constants.Cookies.User, userId);\n return response;\n }\n\n const cabinIdRequest = createCabinIdRequest(_request);\n\n const requestState = await cabinIdClient.authenticateRequest(\n cabinIdRequest,\n options\n );\n\n const authObject = requestState.toAuth();\n\n const redirectToSignIn = createMiddlewareRedirectToSignIn(cabinIdRequest);\n\n const protect = createMiddlewareProtect(\n cabinIdRequest,\n authObject,\n redirectToSignIn\n );\n\n const authObjWithMethods: CabinIdMiddlewareAuthObject = Object.assign(\n authObject,\n { protect, redirectToSignIn }\n );\n\n let handlerResult: Response = NextResponse.next();\n\n try {\n handlerResult =\n (await handler?.(() => authObjWithMethods, _request, _event)) ||\n handlerResult;\n } catch (e: any) {\n handlerResult = handleControlFlowErrors(e, cabinIdRequest, requestState);\n }\n\n if (isRedirect(handlerResult)) {\n return serverRedirectWithAuth(cabinIdRequest, handlerResult);\n }\n\n decorateRequest(\n cabinIdRequest,\n handlerResult,\n requestState,\n options.secretKey\n );\n\n // TODO @nikos: we need to make this more generic\n // and move the logic in clerk/backend\n if (requestState.headers) {\n requestState.headers.forEach((value, key) => {\n handlerResult.headers.append(key, value);\n });\n }\n\n return handlerResult;\n };\n\n // If we have a request and event, we're being called as a middleware directly\n // eg, export default clerkMiddleware;\n if (request && event) {\n return nextMiddleware(request, event);\n }\n\n // Otherwise, return a middleware that can be called with a request and event\n // eg, export default clerkMiddleware(auth => { ... });\n return nextMiddleware;\n};\n\nexport { authMiddleware };\n\nconst createMiddlewareRedirectToSignIn = (\n cabinIdRequest: CabinIdRequest\n): CabinIdMiddlewareAuthObject['redirectToSignIn'] => {\n return (opts = {}) => {\n const err = new Error(CONTROL_FLOW_ERROR.REDIRECT_TO_SIGN_IN) as any;\n err.returnBackUrl =\n opts.returnBackUrl === null\n ? ''\n : opts.returnBackUrl || cabinIdRequest.cabinIdUrl.toString();\n throw err;\n };\n};\n\nconst createMiddlewareProtect = (\n cabinIdRequest: CabinIdRequest,\n authObject: AuthObject,\n redirectToSignIn: RedirectFun<Response>\n): CabinIdMiddlewareAuthObject['protect'] => {\n return ((_: any, options: any) => {\n const notFound = () => {\n throw new Error(CONTROL_FLOW_ERROR.FORCE_NOT_FOUND) as any;\n };\n\n const redirect = (url: string) => {\n const err = new Error(CONTROL_FLOW_ERROR.REDIRECT_TO_URL) as any;\n err.redirectUrl = url;\n throw err;\n };\n\n return createProtect({\n request: cabinIdRequest,\n redirect,\n notFound,\n authObject,\n redirectToSignIn,\n })(options);\n }) as AuthProtect;\n};\n\n// Handle errors thrown by protect() and redirectToSignIn() calls,\n// as we want to align the APIs between middleware, pages and route handlers\n// Normally, middleware requires to explicitly return a response, but we want to\n// avoid discrepancies between the APIs as it's easy to miss the `return` statement\n// especially when copy-pasting code from one place to another.\n// This function handles the known errors thrown by the APIs described above,\n// and returns the appropriate response.\nconst handleControlFlowErrors = (\n e: any,\n cabinIdRequest: CabinIdRequest,\n requestState: RequestState\n): Response => {\n switch (e.message) {\n case CONTROL_FLOW_ERROR.FORCE_NOT_FOUND:\n // Rewrite to a bogus URL to force not found error\n return setHeader(\n NextResponse.rewrite(\n `${cabinIdRequest.cabinIdUrl.origin}/cabin_${Date.now()}`\n ),\n constants.Headers.AuthReason,\n 'protect-rewrite'\n );\n case CONTROL_FLOW_ERROR.REDIRECT_TO_URL:\n return redirectAdapter(e.redirectUrl);\n case CONTROL_FLOW_ERROR.REDIRECT_TO_SIGN_IN:\n return createRedirect({\n redirectAdapter,\n baseUrl: cabinIdRequest.cabinIdUrl,\n signInUrl: requestState.signInUrl,\n signUpUrl: requestState.signUpUrl,\n publishableKey: requestState.publishableKey,\n }).redirectToSignIn({ returnBackUrl: e.returnBackUrl });\n default:\n throw e;\n }\n};\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var protect_exports = {};
|
|
20
|
+
__export(protect_exports, {
|
|
21
|
+
createProtect: () => createProtect
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(protect_exports);
|
|
24
|
+
var import_constants = require("../constants");
|
|
25
|
+
const createProtect = (opts) => {
|
|
26
|
+
const { redirectToSignIn, authObject, redirect, notFound, request } = opts;
|
|
27
|
+
return (...args) => {
|
|
28
|
+
var _a, _b, _c, _d, _e, _f;
|
|
29
|
+
const optionValuesAsParam = ((_a = args[0]) == null ? void 0 : _a.unauthenticatedUrl) || ((_b = args[0]) == null ? void 0 : _b.unauthorizedUrl);
|
|
30
|
+
const paramsOrFunction = optionValuesAsParam ? void 0 : args[0];
|
|
31
|
+
const unauthenticatedUrl = ((_c = args[0]) == null ? void 0 : _c.unauthenticatedUrl) || ((_d = args[1]) == null ? void 0 : _d.unauthenticatedUrl);
|
|
32
|
+
const unauthorizedUrl = ((_e = args[0]) == null ? void 0 : _e.unauthorizedUrl) || ((_f = args[1]) == null ? void 0 : _f.unauthorizedUrl);
|
|
33
|
+
const handleUnauthenticated = () => {
|
|
34
|
+
if (unauthenticatedUrl) {
|
|
35
|
+
return redirect(unauthenticatedUrl);
|
|
36
|
+
}
|
|
37
|
+
if (isPageRequest(request)) {
|
|
38
|
+
return redirectToSignIn();
|
|
39
|
+
}
|
|
40
|
+
return notFound();
|
|
41
|
+
};
|
|
42
|
+
const handleUnauthorized = () => {
|
|
43
|
+
if (unauthorizedUrl) {
|
|
44
|
+
return redirect(unauthorizedUrl);
|
|
45
|
+
}
|
|
46
|
+
return notFound();
|
|
47
|
+
};
|
|
48
|
+
if (!authObject.userId) {
|
|
49
|
+
return handleUnauthenticated();
|
|
50
|
+
}
|
|
51
|
+
if (!paramsOrFunction) {
|
|
52
|
+
return authObject;
|
|
53
|
+
}
|
|
54
|
+
return handleUnauthorized();
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const isServerActionRequest = (req) => {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
return !!req.headers.get(import_constants.constants.NextHeaders.NextUrl) && (((_a = req.headers.get(import_constants.constants.Headers.Accept)) == null ? void 0 : _a.includes("text/x-component")) || ((_b = req.headers.get(import_constants.constants.Headers.ContentType)) == null ? void 0 : _b.includes("multipart/form-data")) || !!req.headers.get(import_constants.constants.NextHeaders.NextAction));
|
|
60
|
+
};
|
|
61
|
+
const isPageRequest = (req) => {
|
|
62
|
+
var _a;
|
|
63
|
+
return req.headers.get(import_constants.constants.Headers.SecFetchDest) === "document" || ((_a = req.headers.get(import_constants.constants.Headers.Accept)) == null ? void 0 : _a.includes("text/html")) || !!req.headers.get(import_constants.constants.NextHeaders.NextUrl) && !isServerActionRequest(req) || !!req.headers.get(import_constants.constants.NextHeaders.NextjsData);
|
|
64
|
+
};
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
createProtect
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=protect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/protect.ts"],"sourcesContent":["import { AuthObject, SignedInAuthObject } from '../tokens/authObjects';\nimport { constants } from '../constants';\nimport { RedirectFun } from './createRedirect';\n\ntype AuthProtectOptions = {\n unauthorizedUrl?: string;\n unauthenticatedUrl?: string;\n};\n\n/**\n * Throws a Nextjs notFound error if user is not authenticated or authorized.\n */\nexport interface AuthProtect {\n // (\n // params?: CheckAuthorizationParamsWithCustomPermissions,\n // options?: AuthProtectOptions\n // ): SignedInAuthObject;\n\n // (\n // params?: (has: CheckAuthorizationWithCustomPermissions) => boolean,\n // options?: AuthProtectOptions\n // ): SignedInAuthObject;\n\n (options?: AuthProtectOptions): SignedInAuthObject;\n}\n\nexport const createProtect = (opts: {\n request: Request;\n authObject: AuthObject;\n /**\n * middleware and pages throw a notFound error if signed out\n * but the middleware needs to throw an error it can catch\n * use this callback to customise the behavior\n */\n notFound: () => never;\n /**\n * see {@link notFound} above\n */\n redirect: (url: string) => void;\n /**\n * protect() in middleware redirects to signInUrl if signed out\n * protect() in pages throws a notFound error if signed out\n * use this callback to customise the behavior\n */\n redirectToSignIn: RedirectFun<unknown>;\n}): AuthProtect => {\n const { redirectToSignIn, authObject, redirect, notFound, request } = opts;\n\n return ((...args: any[]) => {\n const optionValuesAsParam =\n args[0]?.unauthenticatedUrl || args[0]?.unauthorizedUrl;\n const paramsOrFunction = optionValuesAsParam ? undefined : args[0];\n const unauthenticatedUrl = (args[0]?.unauthenticatedUrl ||\n args[1]?.unauthenticatedUrl) as string | undefined;\n const unauthorizedUrl = (args[0]?.unauthorizedUrl ||\n args[1]?.unauthorizedUrl) as string | undefined;\n\n const handleUnauthenticated = () => {\n if (unauthenticatedUrl) {\n return redirect(unauthenticatedUrl);\n }\n if (isPageRequest(request)) {\n // TODO: Handle runtime values. What happens if runtime values are set in middleware and in ClerkProvider as well?\n return redirectToSignIn();\n }\n return notFound();\n };\n\n const handleUnauthorized = () => {\n if (unauthorizedUrl) {\n return redirect(unauthorizedUrl);\n }\n return notFound();\n };\n\n /**\n * User is not authenticated\n */\n if (!authObject.userId) {\n return handleUnauthenticated();\n }\n\n /**\n * User is authenticated\n */\n if (!paramsOrFunction) {\n return authObject;\n }\n\n /**\n * if a function is passed and returns false then throw not found\n */\n // if (typeof paramsOrFunction === 'function') {\n // if (paramsOrFunction(authObject.has)) {\n // return authObject;\n // }\n // return handleUnauthorized();\n // }\n\n /**\n * Checking if user is authorized when permission or role is passed\n */\n // if (authObject.has(paramsOrFunction)) {\n // return authObject;\n // }\n\n return handleUnauthorized();\n }) as AuthProtect;\n};\n\nconst isServerActionRequest = (req: Request) => {\n return (\n !!req.headers.get(constants.NextHeaders.NextUrl) &&\n (req.headers.get(constants.Headers.Accept)?.includes('text/x-component') ||\n req.headers\n .get(constants.Headers.ContentType)\n ?.includes('multipart/form-data') ||\n !!req.headers.get(constants.NextHeaders.NextAction))\n );\n};\n\nconst isPageRequest = (req: Request): boolean => {\n return (\n req.headers.get(constants.Headers.SecFetchDest) === 'document' ||\n req.headers.get(constants.Headers.Accept)?.includes('text/html') ||\n (!!req.headers.get(constants.NextHeaders.NextUrl) &&\n !isServerActionRequest(req)) ||\n !!req.headers.get(constants.NextHeaders.NextjsData)\n );\n};\n\n// In case we want to handle router handlers and server actions differently in the future\n// const isRouteHandler = (req: Request) => {\n// return !isPageRequest(req) && !isServerAction(req);\n// };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAA0B;AAyBnB,MAAM,gBAAgB,CAAC,SAmBX;AACjB,QAAM,EAAE,kBAAkB,YAAY,UAAU,UAAU,QAAQ,IAAI;AAEtE,SAAQ,IAAI,SAAgB;AAhD9B;AAiDI,UAAM,wBACJ,UAAK,CAAC,MAAN,mBAAS,yBAAsB,UAAK,CAAC,MAAN,mBAAS;AAC1C,UAAM,mBAAmB,sBAAsB,SAAY,KAAK,CAAC;AACjE,UAAM,uBAAsB,UAAK,CAAC,MAAN,mBAAS,yBACnC,UAAK,CAAC,MAAN,mBAAS;AACX,UAAM,oBAAmB,UAAK,CAAC,MAAN,mBAAS,sBAChC,UAAK,CAAC,MAAN,mBAAS;AAEX,UAAM,wBAAwB,MAAM;AAClC,UAAI,oBAAoB;AACtB,eAAO,SAAS,kBAAkB;AAAA,MACpC;AACA,UAAI,cAAc,OAAO,GAAG;AAE1B,eAAO,iBAAiB;AAAA,MAC1B;AACA,aAAO,SAAS;AAAA,IAClB;AAEA,UAAM,qBAAqB,MAAM;AAC/B,UAAI,iBAAiB;AACnB,eAAO,SAAS,eAAe;AAAA,MACjC;AACA,aAAO,SAAS;AAAA,IAClB;AAKA,QAAI,CAAC,WAAW,QAAQ;AACtB,aAAO,sBAAsB;AAAA,IAC/B;AAKA,QAAI,CAAC,kBAAkB;AACrB,aAAO;AAAA,IACT;AAmBA,WAAO,mBAAmB;AAAA,EAC5B;AACF;AAEA,MAAM,wBAAwB,CAAC,QAAiB;AA9GhD;AA+GE,SACE,CAAC,CAAC,IAAI,QAAQ,IAAI,2BAAU,YAAY,OAAO,QAC9C,SAAI,QAAQ,IAAI,2BAAU,QAAQ,MAAM,MAAxC,mBAA2C,SAAS,0BACnD,SAAI,QACD,IAAI,2BAAU,QAAQ,WAAW,MADpC,mBAEI,SAAS,2BACb,CAAC,CAAC,IAAI,QAAQ,IAAI,2BAAU,YAAY,UAAU;AAExD;AAEA,MAAM,gBAAgB,CAAC,QAA0B;AAzHjD;AA0HE,SACE,IAAI,QAAQ,IAAI,2BAAU,QAAQ,YAAY,MAAM,gBACpD,SAAI,QAAQ,IAAI,2BAAU,QAAQ,MAAM,MAAxC,mBAA2C,SAAS,iBACnD,CAAC,CAAC,IAAI,QAAQ,IAAI,2BAAU,YAAY,OAAO,KAC9C,CAAC,sBAAsB,GAAG,KAC5B,CAAC,CAAC,IAAI,QAAQ,IAAI,2BAAU,YAAY,UAAU;AAEtD;","names":[]}
|
|
@@ -28,6 +28,7 @@ const createRouteMatcher = (routes) => {
|
|
|
28
28
|
}
|
|
29
29
|
const routePatterns = [routes || ""].flat().filter(Boolean);
|
|
30
30
|
const matchers = precomputePathRegex(routePatterns);
|
|
31
|
+
console.log(matchers);
|
|
31
32
|
return (req) => matchers.some((matcher) => matcher.test(req.nextUrl.pathname));
|
|
32
33
|
};
|
|
33
34
|
const precomputePathRegex = (patterns) => {
|