@cabin-id/nextjs 0.0.1
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 +42 -0
- package/dist/cjs/api/getUserInfo.js.map +1 -0
- package/dist/cjs/client/provider.js +57 -0
- package/dist/cjs/client/provider.js.map +1 -0
- package/dist/cjs/component.client.js +2 -0
- package/dist/cjs/component.client.js.map +1 -0
- package/dist/cjs/component.server.js +29 -0
- package/dist/cjs/component.server.js.map +1 -0
- package/dist/cjs/components/SignInButton.js +58 -0
- package/dist/cjs/components/SignInButton.js.map +1 -0
- package/dist/cjs/components/index.js +29 -0
- package/dist/cjs/components/index.js.map +1 -0
- package/dist/cjs/constants.js +121 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/global.d.js +17 -0
- package/dist/cjs/global.d.js.map +1 -0
- package/dist/cjs/hooks/index.js +29 -0
- package/dist/cjs/hooks/index.js.map +1 -0
- package/dist/cjs/hooks/useUser.js +48 -0
- package/dist/cjs/hooks/useUser.js.map +1 -0
- package/dist/cjs/icons/logo.js +98 -0
- package/dist/cjs/icons/logo.js.map +1 -0
- package/dist/cjs/index.js +44 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/server/auth.js +37 -0
- package/dist/cjs/server/auth.js.map +1 -0
- package/dist/cjs/server/createRedirect.js +89 -0
- package/dist/cjs/server/createRedirect.js.map +1 -0
- package/dist/cjs/server/getCurrentUser.js +43 -0
- package/dist/cjs/server/getCurrentUser.js.map +1 -0
- package/dist/cjs/server/middleware.js +185 -0
- package/dist/cjs/server/middleware.js.map +1 -0
- package/dist/cjs/server/routeMatcher.js +42 -0
- package/dist/cjs/server/routeMatcher.js.map +1 -0
- package/dist/cjs/server/serverRedirectWithAuth.js +39 -0
- package/dist/cjs/server/serverRedirectWithAuth.js.map +1 -0
- package/dist/cjs/server/type.js +17 -0
- package/dist/cjs/server/type.js.map +1 -0
- package/dist/cjs/server/utils.js +107 -0
- package/dist/cjs/server/utils.js.map +1 -0
- package/dist/cjs/styles/global.css +334 -0
- package/dist/cjs/styles/global.css.map +1 -0
- package/dist/cjs/types.js +17 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils/assertValidSecretKey.js +35 -0
- package/dist/cjs/utils/assertValidSecretKey.js.map +1 -0
- package/dist/cjs/utils/isomorphicAtob.js +36 -0
- package/dist/cjs/utils/isomorphicAtob.js.map +1 -0
- package/dist/cjs/utils/isomorphicBtoa.js +36 -0
- package/dist/cjs/utils/isomorphicBtoa.js.map +1 -0
- package/dist/cjs/utils/key.js +49 -0
- package/dist/cjs/utils/key.js.map +1 -0
- package/dist/cjs/utils/path.js +33 -0
- package/dist/cjs/utils/path.js.map +1 -0
- package/dist/cjs/utils/response.js +76 -0
- package/dist/cjs/utils/response.js.map +1 -0
- package/dist/cjs/utils.js +42 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/esm/api/getUserInfo.js +18 -0
- package/dist/esm/api/getUserInfo.js.map +1 -0
- package/dist/esm/client/provider.js +22 -0
- package/dist/esm/client/provider.js.map +1 -0
- package/dist/esm/component.client.js +1 -0
- package/dist/esm/component.client.js.map +1 -0
- package/dist/esm/component.server.js +5 -0
- package/dist/esm/component.server.js.map +1 -0
- package/dist/esm/components/SignInButton.js +24 -0
- package/dist/esm/components/SignInButton.js.map +1 -0
- package/dist/esm/components/index.js +5 -0
- package/dist/esm/components/index.js.map +1 -0
- package/dist/esm/constants.js +87 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/global.d.js +1 -0
- package/dist/esm/global.d.js.map +1 -0
- package/dist/esm/hooks/index.js +5 -0
- package/dist/esm/hooks/index.js.map +1 -0
- package/dist/esm/hooks/useUser.js +14 -0
- package/dist/esm/hooks/useUser.js.map +1 -0
- package/dist/esm/icons/logo.js +64 -0
- package/dist/esm/icons/logo.js.map +1 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/server/auth.js +13 -0
- package/dist/esm/server/auth.js.map +1 -0
- package/dist/esm/server/createRedirect.js +65 -0
- package/dist/esm/server/createRedirect.js.map +1 -0
- package/dist/esm/server/getCurrentUser.js +19 -0
- package/dist/esm/server/getCurrentUser.js.map +1 -0
- package/dist/esm/server/middleware.js +166 -0
- package/dist/esm/server/middleware.js.map +1 -0
- package/dist/esm/server/routeMatcher.js +18 -0
- package/dist/esm/server/routeMatcher.js.map +1 -0
- package/dist/esm/server/serverRedirectWithAuth.js +15 -0
- package/dist/esm/server/serverRedirectWithAuth.js.map +1 -0
- package/dist/esm/server/type.js +1 -0
- package/dist/esm/server/type.js.map +1 -0
- package/dist/esm/server/utils.js +79 -0
- package/dist/esm/server/utils.js.map +1 -0
- package/dist/esm/styles/global.css +334 -0
- package/dist/esm/styles/global.css.map +1 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils/assertValidSecretKey.js +11 -0
- package/dist/esm/utils/assertValidSecretKey.js.map +1 -0
- package/dist/esm/utils/isomorphicAtob.js +12 -0
- package/dist/esm/utils/isomorphicAtob.js.map +1 -0
- package/dist/esm/utils/isomorphicBtoa.js +12 -0
- package/dist/esm/utils/isomorphicBtoa.js.map +1 -0
- package/dist/esm/utils/key.js +24 -0
- package/dist/esm/utils/key.js.map +1 -0
- package/dist/esm/utils/path.js +9 -0
- package/dist/esm/utils/path.js.map +1 -0
- package/dist/esm/utils/response.js +49 -0
- package/dist/esm/utils/response.js.map +1 -0
- package/dist/esm/utils.js +18 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/types/api/getUserInfo.d.ts.map +1 -0
- package/dist/types/client/provider.d.ts.map +1 -0
- package/dist/types/component.client.d.ts.map +1 -0
- package/dist/types/component.server.d.ts.map +1 -0
- package/dist/types/components/SignInButton.d.ts.map +1 -0
- package/dist/types/components/index.d.ts.map +1 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/hooks/index.d.ts.map +1 -0
- package/dist/types/hooks/useUser.d.ts.map +1 -0
- package/dist/types/icons/logo.d.ts.map +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/server/auth.d.ts.map +1 -0
- package/dist/types/server/createRedirect.d.ts.map +1 -0
- package/dist/types/server/getCurrentUser.d.ts.map +1 -0
- package/dist/types/server/middleware.d.ts.map +1 -0
- package/dist/types/server/routeMatcher.d.ts.map +1 -0
- package/dist/types/server/serverRedirectWithAuth.d.ts.map +1 -0
- package/dist/types/server/type.d.ts.map +1 -0
- package/dist/types/server/utils.d.ts.map +1 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils/assertValidSecretKey.d.ts.map +1 -0
- package/dist/types/utils/isomorphicAtob.d.ts.map +1 -0
- package/dist/types/utils/isomorphicBtoa.d.ts.map +1 -0
- package/dist/types/utils/key.d.ts.map +1 -0
- package/dist/types/utils/path.d.ts.map +1 -0
- package/dist/types/utils/response.d.ts.map +1 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import {
|
|
3
|
+
constants,
|
|
4
|
+
CUSTOM_SIGN_IN_URL,
|
|
5
|
+
PUBLISHABLE_KEY,
|
|
6
|
+
SECRET_KEY
|
|
7
|
+
} from "../constants";
|
|
8
|
+
import { createRouteMatcher } from "./routeMatcher";
|
|
9
|
+
import {
|
|
10
|
+
apiEndpointUnauthorizedNextResponse,
|
|
11
|
+
assertKey,
|
|
12
|
+
redirectAdapter
|
|
13
|
+
} from "./utils";
|
|
14
|
+
import { isRedirect, mergeResponses, setHeader } from "../utils/response";
|
|
15
|
+
import { createRedirect } from "./createRedirect";
|
|
16
|
+
const DEFAULT_CONFIG_MATCHER = [
|
|
17
|
+
"/((?!.+\\.[\\w]+$|_next).*)",
|
|
18
|
+
"/",
|
|
19
|
+
"/(api|trpc)(.*)"
|
|
20
|
+
];
|
|
21
|
+
const DEFAULT_IGNORED_ROUTES = [`/((?!api|trpc))(_next.*|.+\\.[\\w]+$)`];
|
|
22
|
+
const DEFAULT_API_ROUTES = ["/api/(.*)", "/trpc/(.*)"];
|
|
23
|
+
const authMiddleware = (...args) => {
|
|
24
|
+
const [params = {}] = args;
|
|
25
|
+
const publishableKey = assertKey(
|
|
26
|
+
params.publishableKey || PUBLISHABLE_KEY,
|
|
27
|
+
() => {
|
|
28
|
+
throw new Error("Publish Key is not exist");
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
const secretKey = assertKey(params.secretKey || SECRET_KEY, () => {
|
|
32
|
+
throw new Error("Secret Key is not valid");
|
|
33
|
+
});
|
|
34
|
+
const signInUrl = params.signInUrl || CUSTOM_SIGN_IN_URL;
|
|
35
|
+
const signUpUrl = params.signUpUrl || CUSTOM_SIGN_IN_URL;
|
|
36
|
+
const options = {
|
|
37
|
+
...params,
|
|
38
|
+
publishableKey,
|
|
39
|
+
secretKey,
|
|
40
|
+
signInUrl,
|
|
41
|
+
signUpUrl
|
|
42
|
+
};
|
|
43
|
+
const isIgnoredRoute = createRouteMatcher(
|
|
44
|
+
options.ignoredRoutes || DEFAULT_IGNORED_ROUTES
|
|
45
|
+
);
|
|
46
|
+
const isPublicRoute = createRouteMatcher(
|
|
47
|
+
withDefaultPublicRoutes(options.publicRoutes)
|
|
48
|
+
);
|
|
49
|
+
const isApiRoute = createApiRoutes(options.apiRoutes);
|
|
50
|
+
const defaultAfterAuth = createDefaultAfterAuth(
|
|
51
|
+
isPublicRoute,
|
|
52
|
+
isApiRoute,
|
|
53
|
+
options
|
|
54
|
+
);
|
|
55
|
+
return async (_req, evt) => {
|
|
56
|
+
const url = _req.nextUrl;
|
|
57
|
+
const accessToken = url.searchParams.get(constants.QueryParams.Token);
|
|
58
|
+
const userId = url.searchParams.get(constants.QueryParams.UserId);
|
|
59
|
+
if (isIgnoredRoute(_req) || isPublicRoute(_req)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const nextRequest = _req;
|
|
63
|
+
const beforeAuthRes = await (options.beforeAuth && options.beforeAuth(nextRequest, evt));
|
|
64
|
+
if (beforeAuthRes === false) {
|
|
65
|
+
return setHeader(
|
|
66
|
+
NextResponse.next(),
|
|
67
|
+
constants.Headers.AuthReason,
|
|
68
|
+
"skip"
|
|
69
|
+
);
|
|
70
|
+
} else if (beforeAuthRes && isRedirect(beforeAuthRes)) {
|
|
71
|
+
return setHeader(
|
|
72
|
+
beforeAuthRes,
|
|
73
|
+
constants.Headers.AuthReason,
|
|
74
|
+
"before-auth-redirect"
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
const requestState = {
|
|
78
|
+
token: accessToken,
|
|
79
|
+
userId
|
|
80
|
+
};
|
|
81
|
+
const auth = {
|
|
82
|
+
...requestState,
|
|
83
|
+
isPublicRoute: isPublicRoute(nextRequest),
|
|
84
|
+
isApiRoute: isApiRoute(nextRequest)
|
|
85
|
+
};
|
|
86
|
+
const afterAuthRes = await (options.afterAuth || defaultAfterAuth)(
|
|
87
|
+
auth,
|
|
88
|
+
nextRequest,
|
|
89
|
+
evt
|
|
90
|
+
);
|
|
91
|
+
const finalRes = mergeResponses(beforeAuthRes, afterAuthRes) || NextResponse.next();
|
|
92
|
+
if (accessToken && userId) {
|
|
93
|
+
const path = url.pathname;
|
|
94
|
+
const response = NextResponse.redirect(new URL(path || "/", _req.url));
|
|
95
|
+
response.cookies.set(constants.Cookies.Client, accessToken);
|
|
96
|
+
response.cookies.set(constants.Cookies.User, userId);
|
|
97
|
+
return response;
|
|
98
|
+
}
|
|
99
|
+
const result = (
|
|
100
|
+
// decorateRequest(_req, finalRes, requestState, secretKey) ||
|
|
101
|
+
NextResponse.next()
|
|
102
|
+
);
|
|
103
|
+
return result;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
const withDefaultPublicRoutes = (publicRoutes) => {
|
|
107
|
+
if (typeof publicRoutes === "function") {
|
|
108
|
+
return publicRoutes;
|
|
109
|
+
}
|
|
110
|
+
const routes = [publicRoutes || ""].flat().filter(Boolean);
|
|
111
|
+
const signInUrl = process.env.NEXT_PUBLIC_CLERK_SIGN_IN_URL || "";
|
|
112
|
+
if (signInUrl) {
|
|
113
|
+
routes.push(matchRoutesStartingWith(signInUrl));
|
|
114
|
+
}
|
|
115
|
+
const signUpUrl = process.env.NEXT_PUBLIC_CLERK_SIGN_UP_URL || "";
|
|
116
|
+
if (signUpUrl) {
|
|
117
|
+
routes.push(matchRoutesStartingWith(signUpUrl));
|
|
118
|
+
}
|
|
119
|
+
return routes;
|
|
120
|
+
};
|
|
121
|
+
const matchRoutesStartingWith = (path) => {
|
|
122
|
+
path = path.replace(/\/$/, "");
|
|
123
|
+
return new RegExp(`^${path}(/.*)?$`);
|
|
124
|
+
};
|
|
125
|
+
const isRequestMethodIndicatingApiRoute = (req) => {
|
|
126
|
+
const requestMethod = req.method.toLowerCase();
|
|
127
|
+
return !["get", "head", "options"].includes(requestMethod);
|
|
128
|
+
};
|
|
129
|
+
const isRequestContentTypeJson = (req) => {
|
|
130
|
+
const requestContentType = req.headers.get(constants.Headers.ContentType);
|
|
131
|
+
return requestContentType === constants.ContentTypes.Json;
|
|
132
|
+
};
|
|
133
|
+
const createApiRoutes = (apiRoutes) => {
|
|
134
|
+
if (apiRoutes) {
|
|
135
|
+
return createRouteMatcher(apiRoutes);
|
|
136
|
+
}
|
|
137
|
+
const isDefaultApiRoute = createRouteMatcher(DEFAULT_API_ROUTES);
|
|
138
|
+
return (req) => isDefaultApiRoute(req) || isRequestMethodIndicatingApiRoute(req) || isRequestContentTypeJson(req);
|
|
139
|
+
};
|
|
140
|
+
const createDefaultAfterAuth = (isPublicRoute, isApiRoute, options) => {
|
|
141
|
+
return (auth, req) => {
|
|
142
|
+
if (!auth.userId && !isPublicRoute(req)) {
|
|
143
|
+
if (isApiRoute(req)) {
|
|
144
|
+
return apiEndpointUnauthorizedNextResponse();
|
|
145
|
+
}
|
|
146
|
+
return createRedirect({
|
|
147
|
+
redirectAdapter,
|
|
148
|
+
signInUrl: options.signInUrl,
|
|
149
|
+
signUpUrl: options.signUpUrl,
|
|
150
|
+
publishableKey: options.publishableKey,
|
|
151
|
+
// We're setting baseUrl to '' here as we want to keep the legacy behavior of
|
|
152
|
+
// the redirectToSignIn, redirectToSignUp helpers in the backend package.
|
|
153
|
+
baseUrl: ""
|
|
154
|
+
}).redirectToSignIn({ returnBackUrl: req.nextUrl.href });
|
|
155
|
+
}
|
|
156
|
+
return NextResponse.next();
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
export {
|
|
160
|
+
DEFAULT_API_ROUTES,
|
|
161
|
+
DEFAULT_CONFIG_MATCHER,
|
|
162
|
+
DEFAULT_IGNORED_ROUTES,
|
|
163
|
+
authMiddleware,
|
|
164
|
+
createDefaultAfterAuth
|
|
165
|
+
};
|
|
166
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +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_SIGN_IN_URL,\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';\nimport { isRedirect, mergeResponses, 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, evt: NextFetchEvent) => {\n const url = _req.nextUrl;\n const accessToken = url.searchParams.get(constants.QueryParams.Token);\n const userId = url.searchParams.get(constants.QueryParams.UserId);\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 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 (isRedirect(finalRes)) {\n // const res = serverRedirectWithAuth(finalRes);\n // return res;\n // }\n\n const result =\n // decorateRequest(_req, finalRes, requestState, secretKey) ||\n NextResponse.next();\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\nexport { authMiddleware };\n"],"mappings":"AAAA,SAAyC,oBAAoB;AAE7D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA6C;AACtD;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AAEP,SAAS,YAAY,gBAAgB,iBA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AQ,OAAO,EAAE;AAC7B,SAAO,IAAI,OAAO,IAAI,IAAI,SAAS;AACrC;AAEA,MAAM,oCAAoC,CAAC,QAA8B;AACvE,QAAM,gBAAgB,IAAI,OAAO,YAAY;AAC7C,SAAO,CAAC,CAAC,OAAO,QAAQ,SAAS,EAAE,SAAS,aAAa;AAC3D;AAEA,MAAM,2BAA2B,CAAC,QAA8B;AAC9D,QAAM,qBAAqB,IAAI,QAAQ,IAAI,UAAU,QAAQ,WAAW;AACxE,SAAO,uBAAuB,UAAU,aAAa;AACvD;AAUA,MAAM,kBAAkB,CACtB,cACoC;AACpC,MAAI,WAAW;AACb,WAAO,mBAAmB,SAAS;AAAA,EACrC;AACA,QAAM,oBAAoB,mBAAmB,kBAAkB;AAC/D,SAAO,CAAC,QACN,kBAAkB,GAAG,KACrB,kCAAkC,GAAG,KACrC,yBAAyB,GAAG;AAChC;AAEO,MAAM,yBAAyB,CACpC,eACA,YACA,YAMG;AACH,SAAO,CAAC,MAAW,QAAqB;AACtC,QAAI,CAAC,KAAK,UAAU,CAAC,cAAc,GAAG,GAAG;AACvC,UAAI,WAAW,GAAG,GAAG;AACnB,eAAO,oCAAoC;AAAA,MAC7C;AACA,aAAO,eAAe;AAAA,QACpB;AAAA,QACA,WAAW,QAAQ;AAAA,QACnB,WAAW,QAAQ;AAAA,QACnB,gBAAgB,QAAQ;AAAA;AAAA;AAAA,QAGxB,SAAS;AAAA,MACX,CAAC,EAAE,iBAAiB,EAAE,eAAe,IAAI,QAAQ,KAAK,CAAC;AAAA,IACzD;AACA,WAAO,aAAa,KAAK;AAAA,EAC3B;AACF;","names":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { paths } from "../utils";
|
|
2
|
+
const createRouteMatcher = (routes) => {
|
|
3
|
+
if (typeof routes === "function") {
|
|
4
|
+
return (req) => routes(req);
|
|
5
|
+
}
|
|
6
|
+
const routePatterns = [routes || ""].flat().filter(Boolean);
|
|
7
|
+
const matchers = precomputePathRegex(routePatterns);
|
|
8
|
+
return (req) => matchers.some((matcher) => matcher.test(req.nextUrl.pathname));
|
|
9
|
+
};
|
|
10
|
+
const precomputePathRegex = (patterns) => {
|
|
11
|
+
return patterns.map(
|
|
12
|
+
(pattern) => pattern instanceof RegExp ? pattern : paths.toRegexp(pattern)
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
createRouteMatcher
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=routeMatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/routeMatcher.ts"],"sourcesContent":["import type Link from \"next/link\";\nimport type { NextRequest } from \"next/server\";\nimport type { Autocomplete } from \"../types\";\nimport { paths } from \"../utils\";\n\ntype WithPathPatternWildcard<T> = `${T & string}(.*)`;\ntype NextTypedRoute<T = Parameters<typeof Link>[\"0\"][\"href\"]> = T extends string\n ? T\n : never;\n\ntype RouteMatcherWithNextTypedRoutes = Autocomplete<\n WithPathPatternWildcard<NextTypedRoute> | NextTypedRoute\n>;\n\nexport type RouteMatcherParam =\n | Array<RegExp | RouteMatcherWithNextTypedRoutes>\n | RegExp\n | RouteMatcherWithNextTypedRoutes\n | ((req: NextRequest) => boolean);\n\nexport const createRouteMatcher = (routes: RouteMatcherParam) => {\n if (typeof routes === \"function\") {\n return (req: NextRequest) => routes(req);\n }\n\n const routePatterns = [routes || \"\"].flat().filter(Boolean);\n const matchers = precomputePathRegex(routePatterns);\n return (req: NextRequest) =>\n matchers.some((matcher) => matcher.test(req.nextUrl.pathname));\n};\n\nconst precomputePathRegex = (patterns: Array<string | RegExp>) => {\n return patterns.map((pattern) =>\n pattern instanceof RegExp ? pattern : paths.toRegexp(pattern),\n );\n};\n"],"mappings":"AAGA,SAAS,aAAa;AAiBf,MAAM,qBAAqB,CAAC,WAA8B;AAC/D,MAAI,OAAO,WAAW,YAAY;AAChC,WAAO,CAAC,QAAqB,OAAO,GAAG;AAAA,EACzC;AAEA,QAAM,gBAAgB,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,OAAO,OAAO;AAC1D,QAAM,WAAW,oBAAoB,aAAa;AAClD,SAAO,CAAC,QACN,SAAS,KAAK,CAAC,YAAY,QAAQ,KAAK,IAAI,QAAQ,QAAQ,CAAC;AACjE;AAEA,MAAM,sBAAsB,CAAC,aAAqC;AAChE,SAAO,SAAS;AAAA,IAAI,CAAC,YACnB,mBAAmB,SAAS,UAAU,MAAM,SAAS,OAAO;AAAA,EAC9D;AACF;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import { constants } from "../constants";
|
|
3
|
+
const serverRedirectWithAuth = (res) => {
|
|
4
|
+
const location = res.headers.get("location");
|
|
5
|
+
const shouldAppendDevBrowser = res.headers.get(constants.Headers.CabinIdRedirectTo) === "true";
|
|
6
|
+
if (shouldAppendDevBrowser && !!location) {
|
|
7
|
+
const url = new URL(location);
|
|
8
|
+
return NextResponse.redirect(url.href, res);
|
|
9
|
+
}
|
|
10
|
+
return res;
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
serverRedirectWithAuth
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=serverRedirectWithAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/serverRedirectWithAuth.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport { constants } from '../constants';\n\nexport const serverRedirectWithAuth = (res: Response) => {\n const location = res.headers.get('location');\n const shouldAppendDevBrowser =\n res.headers.get(constants.Headers.CabinIdRedirectTo) === 'true';\n if (shouldAppendDevBrowser && !!location) {\n // Next.js 12.1+ allows redirects only to absolute URLs\n const url = new URL(location);\n return NextResponse.redirect(url.href, res);\n }\n return res;\n};\n"],"mappings":"AAAA,SAAS,oBAAoB;AAC7B,SAAS,iBAAiB;AAEnB,MAAM,yBAAyB,CAAC,QAAkB;AACvD,QAAM,WAAW,IAAI,QAAQ,IAAI,UAAU;AAC3C,QAAM,yBACJ,IAAI,QAAQ,IAAI,UAAU,QAAQ,iBAAiB,MAAM;AAC3D,MAAI,0BAA0B,CAAC,CAAC,UAAU;AAExC,UAAM,MAAM,IAAI,IAAI,QAAQ;AAC5B,WAAO,aAAa,SAAS,IAAI,MAAM,GAAG;AAAA,EAC5C;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import { constants } from "../constants";
|
|
3
|
+
function assertKey(key, onError) {
|
|
4
|
+
if (!key) {
|
|
5
|
+
onError();
|
|
6
|
+
}
|
|
7
|
+
return key;
|
|
8
|
+
}
|
|
9
|
+
const apiEndpointUnauthorizedNextResponse = () => {
|
|
10
|
+
return NextResponse.json(null, { status: 401, statusText: "Unauthorized" });
|
|
11
|
+
};
|
|
12
|
+
const redirectAdapter = (url) => {
|
|
13
|
+
return NextResponse.redirect(url, {
|
|
14
|
+
headers: { [constants.Headers.CabinIdRedirectTo]: "true" }
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
const OVERRIDE_HEADERS = "x-middleware-override-headers";
|
|
18
|
+
const MIDDLEWARE_HEADER_PREFIX = "x-middleware-request";
|
|
19
|
+
const setRequestHeadersOnNextResponse = (res, req, newHeaders) => {
|
|
20
|
+
if (!res.headers.get(OVERRIDE_HEADERS)) {
|
|
21
|
+
res.headers.set(OVERRIDE_HEADERS, [...req.headers.keys()]);
|
|
22
|
+
req.headers.forEach((val, key) => {
|
|
23
|
+
res.headers.set(`${MIDDLEWARE_HEADER_PREFIX}-${key}`, val);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
Object.entries(newHeaders).forEach(([key, val]) => {
|
|
27
|
+
res.headers.set(
|
|
28
|
+
OVERRIDE_HEADERS,
|
|
29
|
+
`${res.headers.get(OVERRIDE_HEADERS)},${key}`
|
|
30
|
+
);
|
|
31
|
+
res.headers.set(`${MIDDLEWARE_HEADER_PREFIX}-${key}`, val);
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
function createTokenSignature(token, key) {
|
|
35
|
+
return `${token}${key}`;
|
|
36
|
+
}
|
|
37
|
+
function decorateRequest(req, res, requestState, secretKey) {
|
|
38
|
+
const { token } = requestState;
|
|
39
|
+
if (!res) {
|
|
40
|
+
res = NextResponse.next();
|
|
41
|
+
}
|
|
42
|
+
if (res.headers.get(constants.NextHeaders.NextRedirect)) {
|
|
43
|
+
return res;
|
|
44
|
+
}
|
|
45
|
+
let rewriteURL;
|
|
46
|
+
if (res.headers.get(constants.NextHeaders.NextResume) === "1") {
|
|
47
|
+
res.headers.delete(constants.NextHeaders.NextResume);
|
|
48
|
+
rewriteURL = new URL(req.url);
|
|
49
|
+
}
|
|
50
|
+
const rewriteURLHeader = res.headers.get(constants.NextHeaders.NextRewrite);
|
|
51
|
+
if (rewriteURLHeader) {
|
|
52
|
+
const reqURL = new URL(req.url);
|
|
53
|
+
rewriteURL = new URL(rewriteURLHeader);
|
|
54
|
+
if (rewriteURL.origin !== reqURL.origin) {
|
|
55
|
+
return res;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (rewriteURL) {
|
|
59
|
+
setRequestHeadersOnNextResponse(res, req, {
|
|
60
|
+
[constants.Headers.AuthToken]: token || "",
|
|
61
|
+
[constants.Headers.AuthSignature]: token ? createTokenSignature(token, secretKey) : ""
|
|
62
|
+
});
|
|
63
|
+
const origin = rewriteURL == null ? void 0 : rewriteURL.origin;
|
|
64
|
+
const pathName = rewriteURL == null ? void 0 : rewriteURL.pathname;
|
|
65
|
+
res.headers.set(
|
|
66
|
+
constants.NextHeaders.NextRewrite,
|
|
67
|
+
`${origin}${pathName || ""}`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return res;
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
apiEndpointUnauthorizedNextResponse,
|
|
74
|
+
assertKey,
|
|
75
|
+
decorateRequest,
|
|
76
|
+
redirectAdapter,
|
|
77
|
+
setRequestHeadersOnNextResponse
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/utils.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport type { NextRequest } from 'next/server';\nimport { constants } from '../constants';\n\nexport function assertKey(key: string, onError: () => never): string {\n if (!key) {\n onError();\n }\n\n return key;\n}\n\nexport const apiEndpointUnauthorizedNextResponse = () => {\n return NextResponse.json(null, { status: 401, statusText: 'Unauthorized' });\n};\n\nexport const redirectAdapter = (url: string | URL) => {\n return NextResponse.redirect(url, {\n headers: { [constants.Headers.CabinIdRedirectTo]: 'true' },\n });\n};\n\nconst OVERRIDE_HEADERS = 'x-middleware-override-headers';\nconst MIDDLEWARE_HEADER_PREFIX = 'x-middleware-request' as string;\n\nexport const setRequestHeadersOnNextResponse = (\n res: NextResponse | Response,\n req: Request,\n newHeaders: Record<string, string>\n) => {\n if (!res.headers.get(OVERRIDE_HEADERS)) {\n // Emulate a user setting overrides by explicitly adding the required nextjs headers\n // https://github.com/vercel/next.js/pull/41380\n // @ts-expect-error\n res.headers.set(OVERRIDE_HEADERS, [...req.headers.keys()]);\n req.headers.forEach((val, key) => {\n res.headers.set(`${MIDDLEWARE_HEADER_PREFIX}-${key}`, val);\n });\n }\n\n // Now that we have normalised res to include overrides, just append the new header\n Object.entries(newHeaders).forEach(([key, val]) => {\n res.headers.set(\n OVERRIDE_HEADERS,\n `${res.headers.get(OVERRIDE_HEADERS)},${key}`\n );\n res.headers.set(`${MIDDLEWARE_HEADER_PREFIX}-${key}`, val);\n });\n};\n\n/**\n * Compute a cryptographic signature from a session token and provided secret key. Used to validate that the token has not been modified when transferring between middleware and the Next.js origin.\n */\nfunction createTokenSignature(token: string, key: string): string {\n return `${token}${key}`;\n}\n\ntype RequestState = any;\n\n// Auth result will be set as both a query param & header when applicable\nexport function decorateRequest(\n req: NextRequest,\n res: Response,\n requestState: RequestState,\n secretKey: string\n): Response {\n const { token } = requestState;\n // pass-through case, convert to next()\n if (!res) {\n res = NextResponse.next();\n }\n\n // redirect() case, return early\n if (res.headers.get(constants.NextHeaders.NextRedirect)) {\n return res;\n }\n\n let rewriteURL;\n\n // next() case, convert to a rewrite\n if (res.headers.get(constants.NextHeaders.NextResume) === '1') {\n res.headers.delete(constants.NextHeaders.NextResume);\n rewriteURL = new URL(req.url);\n }\n\n // rewrite() case, set auth result only if origin remains the same\n const rewriteURLHeader = res.headers.get(constants.NextHeaders.NextRewrite);\n\n if (rewriteURLHeader) {\n const reqURL = new URL(req.url);\n rewriteURL = new URL(rewriteURLHeader);\n\n // if the origin has changed, return early\n if (rewriteURL.origin !== reqURL.origin) {\n return res;\n }\n }\n\n if (rewriteURL) {\n setRequestHeadersOnNextResponse(res, req, {\n [constants.Headers.AuthToken]: token || '',\n [constants.Headers.AuthSignature]: token\n ? createTokenSignature(token, secretKey)\n : '',\n });\n const origin = rewriteURL?.origin;\n const pathName = rewriteURL?.pathname;\n\n res.headers.set(\n constants.NextHeaders.NextRewrite,\n `${origin}${pathName || ''}`\n );\n }\n return res;\n}\n"],"mappings":"AAAA,SAAS,oBAAoB;AAE7B,SAAS,iBAAiB;AAEnB,SAAS,UAAU,KAAa,SAA8B;AACnE,MAAI,CAAC,KAAK;AACR,YAAQ;AAAA,EACV;AAEA,SAAO;AACT;AAEO,MAAM,sCAAsC,MAAM;AACvD,SAAO,aAAa,KAAK,MAAM,EAAE,QAAQ,KAAK,YAAY,eAAe,CAAC;AAC5E;AAEO,MAAM,kBAAkB,CAAC,QAAsB;AACpD,SAAO,aAAa,SAAS,KAAK;AAAA,IAChC,SAAS,EAAE,CAAC,UAAU,QAAQ,iBAAi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AAa,IAAI,IAAI,gBAAgB;AAGrC,QAAI,WAAW,WAAW,OAAO,QAAQ;AACvC,aAAO;AAAA,IACT;AAAA,EACF;AAEA,MAAI,YAAY;AACd,oCAAgC,KAAK,KAAK;AAAA,MACxC,CAAC,UAAU,QAAQ,SAAS,GAAG,SAAS;AAAA,MACxC,CAAC,UAAU,QAAQ,aAAa,GAAG,QAC/B,qBAAqB,OAAO,SAAS,IACrC;AAAA,IACN,CAAC;AACD,UAAM,SAAS,yCAAY;AAC3B,UAAM,WAAW,yCAAY;AAE7B,QAAI,QAAQ;AAAA,MACV,UAAU,YAAY;AAAA,MACtB,GAAG,MAAM,GAAG,YAAY,EAAE;AAAA,IAC5B;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
*,
|
|
2
|
+
::before,
|
|
3
|
+
::after {
|
|
4
|
+
box-sizing: border-box;
|
|
5
|
+
border-width: 0;
|
|
6
|
+
border-style: solid;
|
|
7
|
+
border-color: #e5e7eb;
|
|
8
|
+
}
|
|
9
|
+
::before,
|
|
10
|
+
::after {
|
|
11
|
+
--tw-content: "";
|
|
12
|
+
}
|
|
13
|
+
html,
|
|
14
|
+
:host {
|
|
15
|
+
line-height: 1.5;
|
|
16
|
+
-webkit-text-size-adjust: 100%;
|
|
17
|
+
-moz-tab-size: 4;
|
|
18
|
+
-o-tab-size: 4;
|
|
19
|
+
tab-size: 4;
|
|
20
|
+
font-family:
|
|
21
|
+
ui-sans-serif,
|
|
22
|
+
system-ui,
|
|
23
|
+
sans-serif,
|
|
24
|
+
"Apple Color Emoji",
|
|
25
|
+
"Segoe UI Emoji",
|
|
26
|
+
"Segoe UI Symbol",
|
|
27
|
+
"Noto Color Emoji";
|
|
28
|
+
font-feature-settings: normal;
|
|
29
|
+
font-variation-settings: normal;
|
|
30
|
+
-webkit-tap-highlight-color: transparent;
|
|
31
|
+
}
|
|
32
|
+
body {
|
|
33
|
+
margin: 0;
|
|
34
|
+
line-height: inherit;
|
|
35
|
+
}
|
|
36
|
+
hr {
|
|
37
|
+
height: 0;
|
|
38
|
+
color: inherit;
|
|
39
|
+
border-top-width: 1px;
|
|
40
|
+
}
|
|
41
|
+
abbr:where([title]) {
|
|
42
|
+
-webkit-text-decoration: underline dotted;
|
|
43
|
+
text-decoration: underline dotted;
|
|
44
|
+
}
|
|
45
|
+
h1,
|
|
46
|
+
h2,
|
|
47
|
+
h3,
|
|
48
|
+
h4,
|
|
49
|
+
h5,
|
|
50
|
+
h6 {
|
|
51
|
+
font-size: inherit;
|
|
52
|
+
font-weight: inherit;
|
|
53
|
+
}
|
|
54
|
+
a {
|
|
55
|
+
color: inherit;
|
|
56
|
+
text-decoration: inherit;
|
|
57
|
+
}
|
|
58
|
+
b,
|
|
59
|
+
strong {
|
|
60
|
+
font-weight: bolder;
|
|
61
|
+
}
|
|
62
|
+
code,
|
|
63
|
+
kbd,
|
|
64
|
+
samp,
|
|
65
|
+
pre {
|
|
66
|
+
font-family:
|
|
67
|
+
ui-monospace,
|
|
68
|
+
SFMono-Regular,
|
|
69
|
+
Menlo,
|
|
70
|
+
Monaco,
|
|
71
|
+
Consolas,
|
|
72
|
+
"Liberation Mono",
|
|
73
|
+
"Courier New",
|
|
74
|
+
monospace;
|
|
75
|
+
font-feature-settings: normal;
|
|
76
|
+
font-variation-settings: normal;
|
|
77
|
+
font-size: 1em;
|
|
78
|
+
}
|
|
79
|
+
small {
|
|
80
|
+
font-size: 80%;
|
|
81
|
+
}
|
|
82
|
+
sub,
|
|
83
|
+
sup {
|
|
84
|
+
font-size: 75%;
|
|
85
|
+
line-height: 0;
|
|
86
|
+
position: relative;
|
|
87
|
+
vertical-align: baseline;
|
|
88
|
+
}
|
|
89
|
+
sub {
|
|
90
|
+
bottom: -0.25em;
|
|
91
|
+
}
|
|
92
|
+
sup {
|
|
93
|
+
top: -0.5em;
|
|
94
|
+
}
|
|
95
|
+
table {
|
|
96
|
+
text-indent: 0;
|
|
97
|
+
border-color: inherit;
|
|
98
|
+
border-collapse: collapse;
|
|
99
|
+
}
|
|
100
|
+
button,
|
|
101
|
+
input,
|
|
102
|
+
optgroup,
|
|
103
|
+
select,
|
|
104
|
+
textarea {
|
|
105
|
+
font-family: inherit;
|
|
106
|
+
font-feature-settings: inherit;
|
|
107
|
+
font-variation-settings: inherit;
|
|
108
|
+
font-size: 100%;
|
|
109
|
+
font-weight: inherit;
|
|
110
|
+
line-height: inherit;
|
|
111
|
+
letter-spacing: inherit;
|
|
112
|
+
color: inherit;
|
|
113
|
+
margin: 0;
|
|
114
|
+
padding: 0;
|
|
115
|
+
}
|
|
116
|
+
button,
|
|
117
|
+
select {
|
|
118
|
+
text-transform: none;
|
|
119
|
+
}
|
|
120
|
+
button,
|
|
121
|
+
input:where([type=button]),
|
|
122
|
+
input:where([type=reset]),
|
|
123
|
+
input:where([type=submit]) {
|
|
124
|
+
-webkit-appearance: button;
|
|
125
|
+
background-color: transparent;
|
|
126
|
+
background-image: none;
|
|
127
|
+
}
|
|
128
|
+
:-moz-focusring {
|
|
129
|
+
outline: auto;
|
|
130
|
+
}
|
|
131
|
+
:-moz-ui-invalid {
|
|
132
|
+
box-shadow: none;
|
|
133
|
+
}
|
|
134
|
+
progress {
|
|
135
|
+
vertical-align: baseline;
|
|
136
|
+
}
|
|
137
|
+
::-webkit-inner-spin-button,
|
|
138
|
+
::-webkit-outer-spin-button {
|
|
139
|
+
height: auto;
|
|
140
|
+
}
|
|
141
|
+
[type=search] {
|
|
142
|
+
-webkit-appearance: textfield;
|
|
143
|
+
outline-offset: -2px;
|
|
144
|
+
}
|
|
145
|
+
::-webkit-search-decoration {
|
|
146
|
+
-webkit-appearance: none;
|
|
147
|
+
}
|
|
148
|
+
::-webkit-file-upload-button {
|
|
149
|
+
-webkit-appearance: button;
|
|
150
|
+
font: inherit;
|
|
151
|
+
}
|
|
152
|
+
summary {
|
|
153
|
+
display: list-item;
|
|
154
|
+
}
|
|
155
|
+
blockquote,
|
|
156
|
+
dl,
|
|
157
|
+
dd,
|
|
158
|
+
h1,
|
|
159
|
+
h2,
|
|
160
|
+
h3,
|
|
161
|
+
h4,
|
|
162
|
+
h5,
|
|
163
|
+
h6,
|
|
164
|
+
hr,
|
|
165
|
+
figure,
|
|
166
|
+
p,
|
|
167
|
+
pre {
|
|
168
|
+
margin: 0;
|
|
169
|
+
}
|
|
170
|
+
fieldset {
|
|
171
|
+
margin: 0;
|
|
172
|
+
padding: 0;
|
|
173
|
+
}
|
|
174
|
+
legend {
|
|
175
|
+
padding: 0;
|
|
176
|
+
}
|
|
177
|
+
ol,
|
|
178
|
+
ul,
|
|
179
|
+
menu {
|
|
180
|
+
list-style: none;
|
|
181
|
+
margin: 0;
|
|
182
|
+
padding: 0;
|
|
183
|
+
}
|
|
184
|
+
dialog {
|
|
185
|
+
padding: 0;
|
|
186
|
+
}
|
|
187
|
+
textarea {
|
|
188
|
+
resize: vertical;
|
|
189
|
+
}
|
|
190
|
+
input::-moz-placeholder,
|
|
191
|
+
textarea::-moz-placeholder {
|
|
192
|
+
opacity: 1;
|
|
193
|
+
color: #9ca3af;
|
|
194
|
+
}
|
|
195
|
+
input::placeholder,
|
|
196
|
+
textarea::placeholder {
|
|
197
|
+
opacity: 1;
|
|
198
|
+
color: #9ca3af;
|
|
199
|
+
}
|
|
200
|
+
button,
|
|
201
|
+
[role=button] {
|
|
202
|
+
cursor: pointer;
|
|
203
|
+
}
|
|
204
|
+
:disabled {
|
|
205
|
+
cursor: default;
|
|
206
|
+
}
|
|
207
|
+
img,
|
|
208
|
+
svg,
|
|
209
|
+
video,
|
|
210
|
+
canvas,
|
|
211
|
+
audio,
|
|
212
|
+
iframe,
|
|
213
|
+
embed,
|
|
214
|
+
object {
|
|
215
|
+
display: block;
|
|
216
|
+
vertical-align: middle;
|
|
217
|
+
}
|
|
218
|
+
img,
|
|
219
|
+
video {
|
|
220
|
+
max-width: 100%;
|
|
221
|
+
height: auto;
|
|
222
|
+
}
|
|
223
|
+
[hidden] {
|
|
224
|
+
display: none;
|
|
225
|
+
}
|
|
226
|
+
*,
|
|
227
|
+
::before,
|
|
228
|
+
::after {
|
|
229
|
+
--tw-border-spacing-x: 0;
|
|
230
|
+
--tw-border-spacing-y: 0;
|
|
231
|
+
--tw-translate-x: 0;
|
|
232
|
+
--tw-translate-y: 0;
|
|
233
|
+
--tw-rotate: 0;
|
|
234
|
+
--tw-skew-x: 0;
|
|
235
|
+
--tw-skew-y: 0;
|
|
236
|
+
--tw-scale-x: 1;
|
|
237
|
+
--tw-scale-y: 1;
|
|
238
|
+
--tw-pan-x: ;
|
|
239
|
+
--tw-pan-y: ;
|
|
240
|
+
--tw-pinch-zoom: ;
|
|
241
|
+
--tw-scroll-snap-strictness: proximity;
|
|
242
|
+
--tw-gradient-from-position: ;
|
|
243
|
+
--tw-gradient-via-position: ;
|
|
244
|
+
--tw-gradient-to-position: ;
|
|
245
|
+
--tw-ordinal: ;
|
|
246
|
+
--tw-slashed-zero: ;
|
|
247
|
+
--tw-numeric-figure: ;
|
|
248
|
+
--tw-numeric-spacing: ;
|
|
249
|
+
--tw-numeric-fraction: ;
|
|
250
|
+
--tw-ring-inset: ;
|
|
251
|
+
--tw-ring-offset-width: 0px;
|
|
252
|
+
--tw-ring-offset-color: #fff;
|
|
253
|
+
--tw-ring-color: rgb(59 130 246 / 0.5);
|
|
254
|
+
--tw-ring-offset-shadow: 0 0 #0000;
|
|
255
|
+
--tw-ring-shadow: 0 0 #0000;
|
|
256
|
+
--tw-shadow: 0 0 #0000;
|
|
257
|
+
--tw-shadow-colored: 0 0 #0000;
|
|
258
|
+
--tw-blur: ;
|
|
259
|
+
--tw-brightness: ;
|
|
260
|
+
--tw-contrast: ;
|
|
261
|
+
--tw-grayscale: ;
|
|
262
|
+
--tw-hue-rotate: ;
|
|
263
|
+
--tw-invert: ;
|
|
264
|
+
--tw-saturate: ;
|
|
265
|
+
--tw-sepia: ;
|
|
266
|
+
--tw-drop-shadow: ;
|
|
267
|
+
--tw-backdrop-blur: ;
|
|
268
|
+
--tw-backdrop-brightness: ;
|
|
269
|
+
--tw-backdrop-contrast: ;
|
|
270
|
+
--tw-backdrop-grayscale: ;
|
|
271
|
+
--tw-backdrop-hue-rotate: ;
|
|
272
|
+
--tw-backdrop-invert: ;
|
|
273
|
+
--tw-backdrop-opacity: ;
|
|
274
|
+
--tw-backdrop-saturate: ;
|
|
275
|
+
--tw-backdrop-sepia: ;
|
|
276
|
+
--tw-contain-size: ;
|
|
277
|
+
--tw-contain-layout: ;
|
|
278
|
+
--tw-contain-paint: ;
|
|
279
|
+
--tw-contain-style: ;
|
|
280
|
+
}
|
|
281
|
+
::backdrop {
|
|
282
|
+
--tw-border-spacing-x: 0;
|
|
283
|
+
--tw-border-spacing-y: 0;
|
|
284
|
+
--tw-translate-x: 0;
|
|
285
|
+
--tw-translate-y: 0;
|
|
286
|
+
--tw-rotate: 0;
|
|
287
|
+
--tw-skew-x: 0;
|
|
288
|
+
--tw-skew-y: 0;
|
|
289
|
+
--tw-scale-x: 1;
|
|
290
|
+
--tw-scale-y: 1;
|
|
291
|
+
--tw-pan-x: ;
|
|
292
|
+
--tw-pan-y: ;
|
|
293
|
+
--tw-pinch-zoom: ;
|
|
294
|
+
--tw-scroll-snap-strictness: proximity;
|
|
295
|
+
--tw-gradient-from-position: ;
|
|
296
|
+
--tw-gradient-via-position: ;
|
|
297
|
+
--tw-gradient-to-position: ;
|
|
298
|
+
--tw-ordinal: ;
|
|
299
|
+
--tw-slashed-zero: ;
|
|
300
|
+
--tw-numeric-figure: ;
|
|
301
|
+
--tw-numeric-spacing: ;
|
|
302
|
+
--tw-numeric-fraction: ;
|
|
303
|
+
--tw-ring-inset: ;
|
|
304
|
+
--tw-ring-offset-width: 0px;
|
|
305
|
+
--tw-ring-offset-color: #fff;
|
|
306
|
+
--tw-ring-color: rgb(59 130 246 / 0.5);
|
|
307
|
+
--tw-ring-offset-shadow: 0 0 #0000;
|
|
308
|
+
--tw-ring-shadow: 0 0 #0000;
|
|
309
|
+
--tw-shadow: 0 0 #0000;
|
|
310
|
+
--tw-shadow-colored: 0 0 #0000;
|
|
311
|
+
--tw-blur: ;
|
|
312
|
+
--tw-brightness: ;
|
|
313
|
+
--tw-contrast: ;
|
|
314
|
+
--tw-grayscale: ;
|
|
315
|
+
--tw-hue-rotate: ;
|
|
316
|
+
--tw-invert: ;
|
|
317
|
+
--tw-saturate: ;
|
|
318
|
+
--tw-sepia: ;
|
|
319
|
+
--tw-drop-shadow: ;
|
|
320
|
+
--tw-backdrop-blur: ;
|
|
321
|
+
--tw-backdrop-brightness: ;
|
|
322
|
+
--tw-backdrop-contrast: ;
|
|
323
|
+
--tw-backdrop-grayscale: ;
|
|
324
|
+
--tw-backdrop-hue-rotate: ;
|
|
325
|
+
--tw-backdrop-invert: ;
|
|
326
|
+
--tw-backdrop-opacity: ;
|
|
327
|
+
--tw-backdrop-saturate: ;
|
|
328
|
+
--tw-backdrop-sepia: ;
|
|
329
|
+
--tw-contain-size: ;
|
|
330
|
+
--tw-contain-layout: ;
|
|
331
|
+
--tw-contain-paint: ;
|
|
332
|
+
--tw-contain-style: ;
|
|
333
|
+
}
|
|
334
|
+
/*# sourceMappingURL=global.css.map */
|