@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 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/response.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\n\nimport { constants } from '../constants';\n\n/**\n * A function that merges two Response objects into a single response.\n * The final response respects the body and the status of the last response,\n * but the cookies and headers of all responses are merged.\n */\nexport const mergeResponses = (...responses: (NextResponse | Response | null | undefined | void)[]) => {\n const normalisedResponses = responses.filter(Boolean).map(res => {\n // If the response is a NextResponse, we can just return it\n if (res instanceof NextResponse) {\n return res;\n }\n\n return new NextResponse(res!.body, res!);\n });\n\n if (normalisedResponses.length === 0) {\n return;\n }\n\n const lastResponse = normalisedResponses[normalisedResponses.length - 1];\n const finalResponse = new NextResponse(lastResponse.body, lastResponse);\n\n for (const response of normalisedResponses) {\n response.headers.forEach((value: string, name: string) => {\n finalResponse.headers.set(name, value);\n });\n\n response.cookies.getAll().forEach(cookie => {\n const { name, value, ...options } = cookie;\n\n finalResponse.cookies.set(name, value, options);\n });\n }\n\n return finalResponse;\n};\n\nexport const isRedirect = (res: Response) => {\n return res.headers.get(constants.NextHeaders.NextRedirect);\n};\n\nexport const setHeader = <T extends Response>(res: T, name: string, val: string): T => {\n res.headers.set(name, val);\n return res;\n};\n\nexport const stringifyHeaders = (headers: { forEach: Headers['forEach'] }) => {\n if (!headers) {\n return JSON.stringify({});\n }\n\n const obj: Record<string, string> = {};\n headers.forEach((value, name) => {\n obj[name] = value;\n });\n return JSON.stringify(obj);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA6B;AAE7B,uBAA0B;AAOnB,MAAM,iBAAiB,IAAI,cAAqE;AACrG,QAAM,sBAAsB,UAAU,OAAO,OAAO,EAAE,IAAI,SAAO;AAE/D,QAAI,eAAe,4BAAc;AAC/B,aAAO;AAAA,IACT;AAEA,WAAO,IAAI,2BAAa,IAAK,MAAM,GAAI;AAAA,EACzC,CAAC;AAED,MAAI,oBAAoB,WAAW,GAAG;AACpC;AAAA,EACF;AAEA,QAAM,eAAe,oBAAoB,oBAAoB,SAAS,CAAC;AACvE,QAAM,gBAAgB,IAAI,2BAAa,aAAa,MAAM,YAAY;AAEtE,aAAW,YAAY,qBAAqB;AAC1C,aAAS,QAAQ,QAAQ,CAAC,OAAe,SAAiB;AACxD,oBAAc,QAAQ,IAAI,MAAM,KAAK;AAAA,IACvC,CAAC;AAED,aAAS,QAAQ,OAAO,EAAE,QAAQ,YAAU;AAC1C,YAAM,EAAE,MAAM,OAAO,GAAG,QAAQ,IAAI;AAEpC,oBAAc,QAAQ,IAAI,MAAM,OAAO,OAAO;AAAA,IAChD,CAAC;AAAA,EACH;AAEA,SAAO;AACT;AAEO,MAAM,aAAa,CAAC,QAAkB;AAC3C,SAAO,IAAI,QAAQ,IAAI,2BAAU,YAAY,YAAY;AAC3D;AAEO,MAAM,YAAY,CAAqB,KAAQ,MAAc,QAAmB;AACrF,MAAI,QAAQ,IAAI,MAAM,GAAG;AACzB,SAAO;AACT;AAEO,MAAM,mBAAmB,CAAC,YAA6C;AAC5E,MAAI,CAAC,SAAS;AACZ,WAAO,KAAK,UAAU,CAAC,CAAC;AAAA,EAC1B;AAEA,QAAM,MAA8B,CAAC;AACrC,UAAQ,QAAQ,CAAC,OAAO,SAAS;AAC/B,QAAI,IAAI,IAAI;AAAA,EACd,CAAC;AACD,SAAO,KAAK,UAAU,GAAG;AAC3B;","names":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 utils_exports = {};
|
|
20
|
+
__export(utils_exports, {
|
|
21
|
+
paths: () => paths
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(utils_exports);
|
|
24
|
+
var import_path_to_regexp = require("path-to-regexp");
|
|
25
|
+
const paths = {
|
|
26
|
+
toRegexp: (path) => {
|
|
27
|
+
try {
|
|
28
|
+
return (0, import_path_to_regexp.pathToRegexp)(path);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Invalid path: ${path}.
|
|
32
|
+
Consult the documentation of path-to-regexp here: https://github.com/pillarjs/path-to-regexp
|
|
33
|
+
${e.message}`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
paths
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import { pathToRegexp } from \"path-to-regexp\";\n\nexport const paths = {\n toRegexp: (path: string) => {\n try {\n return pathToRegexp(path);\n } catch (e: any) {\n throw new Error(\n `Invalid path: ${path}.\\nConsult the documentation of path-to-regexp here: https://github.com/pillarjs/path-to-regexp\\n${e.message}`,\n );\n }\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA6B;AAEtB,MAAM,QAAQ;AAAA,EACnB,UAAU,CAAC,SAAiB;AAC1B,QAAI;AACF,iBAAO,oCAAa,IAAI;AAAA,IAC1B,SAAS,GAAQ;AACf,YAAM,IAAI;AAAA,QACR,iBAAiB,IAAI;AAAA;AAAA,EAAoG,EAAE,OAAO;AAAA,MACpI;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { baseApiUrl } from "src/constants";
|
|
2
|
+
const getUserInfo = async (accessToken) => {
|
|
3
|
+
const res = await fetch(`${baseApiUrl}/user/me`, {
|
|
4
|
+
method: "GET",
|
|
5
|
+
headers: {
|
|
6
|
+
"Content-Type": "application/json",
|
|
7
|
+
Authorization: `Bearer ${accessToken}`
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
if (!res.ok) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return await res.json();
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
getUserInfo
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=getUserInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/api/getUserInfo.ts"],"sourcesContent":["import { baseApiUrl } from 'src/constants';\n\nexport const getUserInfo = async (accessToken: string) => {\n const res = await fetch(`${baseApiUrl}/user/me`, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${accessToken}`,\n },\n });\n if (!res.ok) {\n return null;\n }\n return await res.json();\n};\n"],"mappings":"AAAA,SAAS,kBAAkB;AAEpB,MAAM,cAAc,OAAO,gBAAwB;AACxD,QAAM,MAAM,MAAM,MAAM,GAAG,UAAU,YAAY;AAAA,IAC/C,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,eAAe,UAAU,WAAW;AAAA,IACtC;AAAA,EACF,CAAC;AACD,MAAI,CAAC,IAAI,IAAI;AACX,WAAO;AAAA,EACT;AACA,SAAO,MAAM,IAAI,KAAK;AACxB;","names":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { CUSTOM_AFTER_SIGN_IN_URL, frontendApi } from "../constants";
|
|
3
|
+
const CabinIDContext = React.createContext({
|
|
4
|
+
signInUrl: "",
|
|
5
|
+
user: null
|
|
6
|
+
});
|
|
7
|
+
const CabinIDProvider = ({ children }) => {
|
|
8
|
+
const [user] = React.useState(null);
|
|
9
|
+
const signInUrl = frontendApi || "";
|
|
10
|
+
const redirectUrl = CUSTOM_AFTER_SIGN_IN_URL;
|
|
11
|
+
if (!redirectUrl) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
"You must provide the NEXT_PUBLIC_CABIN_ID_AFTER_SIGN_IN_URL environment variable."
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
return /* @__PURE__ */ React.createElement(CabinIDContext.Provider, { value: { user, signInUrl } }, children);
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
CabinIDContext,
|
|
20
|
+
CabinIDProvider
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/provider.tsx"],"sourcesContent":["import React from 'react';\nimport type { PropsWithChildren } from 'react';\nimport { CabinIDProviderProps, CabinIDUser } from '../types';\nimport { CUSTOM_AFTER_SIGN_IN_URL, frontendApi } from '../constants';\n\nexport const CabinIDContext = React.createContext<CabinIDProviderProps>({\n signInUrl: '',\n user: null,\n});\n\nconst CabinIDProvider = ({ children }: PropsWithChildren<any>) => {\n const [user] = React.useState<CabinIDUser | null>(null);\n const signInUrl = frontendApi || '';\n\n const redirectUrl = CUSTOM_AFTER_SIGN_IN_URL;\n\n if (!redirectUrl) {\n throw new Error(\n 'You must provide the NEXT_PUBLIC_CABIN_ID_AFTER_SIGN_IN_URL environment variable.'\n );\n }\n\n return (\n <CabinIDContext.Provider value={{ user, signInUrl }}>\n {children}\n </CabinIDContext.Provider>\n );\n};\n\nexport { CabinIDProvider };\n"],"mappings":"AAAA,OAAO,WAAW;AAGlB,SAAS,0BAA0B,mBAAmB;AAE/C,MAAM,iBAAiB,MAAM,cAAoC;AAAA,EACtE,WAAW;AAAA,EACX,MAAM;AACR,CAAC;AAED,MAAM,kBAAkB,CAAC,EAAE,SAAS,MAA8B;AAChE,QAAM,CAAC,IAAI,IAAI,MAAM,SAA6B,IAAI;AACtD,QAAM,YAAY,eAAe;AAEjC,QAAM,cAAc;AAEpB,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SACE,oCAAC,eAAe,UAAf,EAAwB,OAAO,EAAE,MAAM,UAAU,KAC/C,QACH;AAEJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=component.client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/component.server.ts"],"sourcesContent":["export { auth } from './server/auth';\n"],"mappings":"AAAA,SAAS,YAAY;","names":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { CabinLogo } from "../icons/logo";
|
|
3
|
+
import { CUSTOM_AFTER_SIGN_IN_URL, frontendApi } from "../constants";
|
|
4
|
+
const SignInButton = () => {
|
|
5
|
+
const signInUrl = React.useMemo(() => {
|
|
6
|
+
const params = new URLSearchParams({
|
|
7
|
+
redirect_url: CUSTOM_AFTER_SIGN_IN_URL
|
|
8
|
+
});
|
|
9
|
+
return frontendApi ? `http://${frontendApi}/sign-in?${params.toString()}` : "#";
|
|
10
|
+
}, [frontendApi, CUSTOM_AFTER_SIGN_IN_URL]);
|
|
11
|
+
return /* @__PURE__ */ React.createElement(
|
|
12
|
+
"a",
|
|
13
|
+
{
|
|
14
|
+
href: signInUrl,
|
|
15
|
+
className: "max-w-48 pl-2 py-2 pr-4 bg-blue-600 rounded-full flex flex-row space-x-2 items-center hover:opacity-90 active:bg-blue-700"
|
|
16
|
+
},
|
|
17
|
+
/* @__PURE__ */ React.createElement(CabinLogo, null),
|
|
18
|
+
/* @__PURE__ */ React.createElement("span", { className: "text-white text-sm" }, "Continue to CabinID")
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
SignInButton
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=SignInButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/SignInButton.tsx"],"sourcesContent":["import React from 'react';\nimport { CabinLogo } from '../icons/logo';\nimport { CUSTOM_AFTER_SIGN_IN_URL, frontendApi } from '../constants';\n\nexport const SignInButton = () => {\n const signInUrl = React.useMemo(() => {\n const params = new URLSearchParams({\n redirect_url: CUSTOM_AFTER_SIGN_IN_URL,\n });\n return frontendApi\n ? `http://${frontendApi}/sign-in?${params.toString()}`\n : '#';\n }, [frontendApi, CUSTOM_AFTER_SIGN_IN_URL]);\n\n return (\n <a\n href={signInUrl}\n className=\"max-w-48 pl-2 py-2 pr-4 bg-blue-600 rounded-full flex flex-row space-x-2 items-center hover:opacity-90 active:bg-blue-700\"\n >\n <CabinLogo />\n <span className=\"text-white text-sm\">Continue to CabinID</span>\n </a>\n );\n};\n"],"mappings":"AAAA,OAAO,WAAW;AAClB,SAAS,iBAAiB;AAC1B,SAAS,0BAA0B,mBAAmB;AAE/C,MAAM,eAAe,MAAM;AAChC,QAAM,YAAY,MAAM,QAAQ,MAAM;AACpC,UAAM,SAAS,IAAI,gBAAgB;AAAA,MACjC,cAAc;AAAA,IAChB,CAAC;AACD,WAAO,cACH,UAAU,WAAW,YAAY,OAAO,SAAS,CAAC,KAClD;AAAA,EACN,GAAG,CAAC,aAAa,wBAAwB,CAAC;AAE1C,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAM;AAAA,MACN,WAAU;AAAA;AAAA,IAEV,oCAAC,eAAU;AAAA,IACX,oCAAC,UAAK,WAAU,wBAAqB,qBAAmB;AAAA,EAC1D;AAEJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/index.ts"],"sourcesContent":["export { SignInButton } from './SignInButton';\n"],"mappings":"AAAA,SAAS,oBAAoB;","names":[]}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { parsePublishableKey } from "./utils/key";
|
|
2
|
+
import { joinPaths } from "./utils/path";
|
|
3
|
+
const API_URL = "https://api.cabinid.dev/";
|
|
4
|
+
const API_VERSION = "v1";
|
|
5
|
+
const PUBLISHABLE_KEY = process.env.NEXT_PUBLIC_CABIN_ID_PUBLISH_KEY || "";
|
|
6
|
+
const SECRET_KEY = process.env.CABIN_ID_SECRET_KEY || "";
|
|
7
|
+
const CUSTOM_SIGN_IN_URL = process.env.NEXT_PUBLIC_CABIN_ID_SIGN_IN_URL || "";
|
|
8
|
+
const CUSTOM_SIGN_Up_URL = process.env.NEXT_PUBLIC_CABIN_ID_SIGN_UP_URL || "";
|
|
9
|
+
const CUSTOM_AFTER_SIGN_IN_URL = process.env.NEXT_PUBLIC_CABIN_ID_AFTER_SIGN_IN_URL || "";
|
|
10
|
+
const CUSTOM_AFTER_SIGN_UP_URL = process.env.NEXT_PUBLIC_CABIN_ID_AFTER_SIGN_UP_URL || "";
|
|
11
|
+
const baseApiUrl = joinPaths(API_URL, API_VERSION);
|
|
12
|
+
const frontendApi = parsePublishableKey(PUBLISHABLE_KEY);
|
|
13
|
+
const Attributes = {
|
|
14
|
+
AuthToken: "__clerkAuthToken",
|
|
15
|
+
AuthSignature: "__clerkAuthSignature",
|
|
16
|
+
AuthStatus: "__clerkAuthStatus",
|
|
17
|
+
AuthReason: "__clerkAuthReason",
|
|
18
|
+
AuthMessage: "__clerkAuthMessage",
|
|
19
|
+
ClerkUrl: "__clerkUrl"
|
|
20
|
+
};
|
|
21
|
+
const Cookies = {
|
|
22
|
+
Session: "__session",
|
|
23
|
+
Client: "__client",
|
|
24
|
+
User: "__user"
|
|
25
|
+
};
|
|
26
|
+
const QueryParams = {
|
|
27
|
+
UserId: "user_id",
|
|
28
|
+
Token: "token"
|
|
29
|
+
};
|
|
30
|
+
const Headers = {
|
|
31
|
+
AuthToken: "x-cabin-id-auth-token",
|
|
32
|
+
AuthSignature: "x-cabin-id-auth-signature",
|
|
33
|
+
AuthStatus: "x-cabin-id-auth-status",
|
|
34
|
+
AuthReason: "x-cabin-id-auth-reason",
|
|
35
|
+
AuthMessage: "x-cabin-id-auth-message",
|
|
36
|
+
CabinIdUrl: "x-cabin-id-cabin-id-url",
|
|
37
|
+
EnableDebug: "x-cabin-id-debug",
|
|
38
|
+
CabinIdRedirectTo: "x-cabin-id-redirect-to",
|
|
39
|
+
CloudFrontForwardedProto: "cloudfront-forwarded-proto",
|
|
40
|
+
Authorization: "authorization",
|
|
41
|
+
ForwardedPort: "x-forwarded-port",
|
|
42
|
+
ForwardedProto: "x-forwarded-proto",
|
|
43
|
+
ForwardedHost: "x-forwarded-host",
|
|
44
|
+
Accept: "accept",
|
|
45
|
+
Referrer: "referer",
|
|
46
|
+
UserAgent: "user-agent",
|
|
47
|
+
Origin: "origin",
|
|
48
|
+
Host: "host",
|
|
49
|
+
ContentType: "content-type",
|
|
50
|
+
SecFetchDest: "sec-fetch-dest",
|
|
51
|
+
Location: "location"
|
|
52
|
+
};
|
|
53
|
+
const ContentTypes = {
|
|
54
|
+
Json: "application/json"
|
|
55
|
+
};
|
|
56
|
+
const NextHeaders = {
|
|
57
|
+
NextRewrite: "x-middleware-rewrite",
|
|
58
|
+
NextResume: "x-middleware-next",
|
|
59
|
+
NextRedirect: "Location",
|
|
60
|
+
// Used by next to identify internal navigation for app router
|
|
61
|
+
NextUrl: "next-url",
|
|
62
|
+
NextAction: "next-action",
|
|
63
|
+
// Used by next to identify internal navigation for pages router
|
|
64
|
+
NextjsData: "x-nextjs-data"
|
|
65
|
+
};
|
|
66
|
+
const constants = {
|
|
67
|
+
Attributes,
|
|
68
|
+
Cookies,
|
|
69
|
+
Headers,
|
|
70
|
+
ContentTypes,
|
|
71
|
+
QueryParams,
|
|
72
|
+
NextHeaders
|
|
73
|
+
};
|
|
74
|
+
export {
|
|
75
|
+
API_URL,
|
|
76
|
+
API_VERSION,
|
|
77
|
+
CUSTOM_AFTER_SIGN_IN_URL,
|
|
78
|
+
CUSTOM_AFTER_SIGN_UP_URL,
|
|
79
|
+
CUSTOM_SIGN_IN_URL,
|
|
80
|
+
CUSTOM_SIGN_Up_URL,
|
|
81
|
+
PUBLISHABLE_KEY,
|
|
82
|
+
SECRET_KEY,
|
|
83
|
+
baseApiUrl,
|
|
84
|
+
constants,
|
|
85
|
+
frontendApi
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/constants.ts"],"sourcesContent":["import { parsePublishableKey } from './utils/key';\nimport { joinPaths } from './utils/path';\n\n/* The line `// export const API_URL = 'https://api.cabinid.dev/';` is a commented-out line of code in\nTypeScript. It is currently not active or being used in the code because it is preceded by `//`,\nwhich makes it a comment. */\nexport const API_URL = 'https://api.cabinid.dev/';\n// export const API_URL = 'http://localhost:3001/';\nexport const API_VERSION = 'v1';\nexport const PUBLISHABLE_KEY =\n process.env.NEXT_PUBLIC_CABIN_ID_PUBLISH_KEY! || '';\nexport const SECRET_KEY = process.env.CABIN_ID_SECRET_KEY! || '';\nexport const CUSTOM_SIGN_IN_URL =\n process.env.NEXT_PUBLIC_CABIN_ID_SIGN_IN_URL! || '';\nexport const CUSTOM_SIGN_Up_URL =\n process.env.NEXT_PUBLIC_CABIN_ID_SIGN_UP_URL! || '';\nexport const CUSTOM_AFTER_SIGN_IN_URL =\n process.env.NEXT_PUBLIC_CABIN_ID_AFTER_SIGN_IN_URL || '';\nexport const CUSTOM_AFTER_SIGN_UP_URL =\n process.env.NEXT_PUBLIC_CABIN_ID_AFTER_SIGN_UP_URL || '';\n\nexport const baseApiUrl = joinPaths(API_URL, API_VERSION);\nexport const frontendApi = parsePublishableKey(PUBLISHABLE_KEY);\n\nconst Attributes = {\n AuthToken: '__clerkAuthToken',\n AuthSignature: '__clerkAuthSignature',\n AuthStatus: '__clerkAuthStatus',\n AuthReason: '__clerkAuthReason',\n AuthMessage: '__clerkAuthMessage',\n ClerkUrl: '__clerkUrl',\n} as const;\n\nconst Cookies = {\n Session: '__session',\n Client: '__client',\n User: '__user',\n} as const;\n\nconst QueryParams = {\n UserId: 'user_id',\n Token: 'token',\n} as const;\n\nconst Headers = {\n AuthToken: 'x-cabin-id-auth-token',\n AuthSignature: 'x-cabin-id-auth-signature',\n AuthStatus: 'x-cabin-id-auth-status',\n AuthReason: 'x-cabin-id-auth-reason',\n AuthMessage: 'x-cabin-id-auth-message',\n CabinIdUrl: 'x-cabin-id-cabin-id-url',\n EnableDebug: 'x-cabin-id-debug',\n CabinIdRedirectTo: 'x-cabin-id-redirect-to',\n CloudFrontForwardedProto: 'cloudfront-forwarded-proto',\n Authorization: 'authorization',\n ForwardedPort: 'x-forwarded-port',\n ForwardedProto: 'x-forwarded-proto',\n ForwardedHost: 'x-forwarded-host',\n Accept: 'accept',\n Referrer: 'referer',\n UserAgent: 'user-agent',\n Origin: 'origin',\n Host: 'host',\n ContentType: 'content-type',\n SecFetchDest: 'sec-fetch-dest',\n Location: 'location',\n} as const;\n\nconst ContentTypes = {\n Json: 'application/json',\n} as const;\n\nconst NextHeaders = {\n NextRewrite: 'x-middleware-rewrite',\n NextResume: 'x-middleware-next',\n NextRedirect: 'Location',\n // Used by next to identify internal navigation for app router\n NextUrl: 'next-url',\n NextAction: 'next-action',\n // Used by next to identify internal navigation for pages router\n NextjsData: 'x-nextjs-data',\n} as const;\n\n/**\n * @internal\n */\nexport const constants = {\n Attributes,\n Cookies,\n Headers,\n ContentTypes,\n QueryParams,\n NextHeaders,\n} as const;\n\nexport type Constants = typeof constants;\n"],"mappings":"AAAA,SAAS,2BAA2B;AACpC,SAAS,iBAAiB;AAKnB,MAAM,UAAU;AAEhB,MAAM,cAAc;AACpB,MAAM,kBACX,QAAQ,IAAI,oCAAqC;AAC5C,MAAM,aAAa,QAAQ,IAAI,uBAAwB;AACvD,MAAM,qBACX,QAAQ,IAAI,oCAAqC;AAC5C,MAAM,qBACX,QAAQ,IAAI,oCAAqC;AAC5C,MAAM,2BACX,QAAQ,IAAI,0CAA0C;AACjD,MAAM,2BACX,QAAQ,IAAI,0CAA0C;AAEjD,MAAM,aAAa,UAAU,SAAS,WAAW;AACjD,MAAM,cAAc,oBAAoB,eAAe;AAE9D,MAAM,aAAa;AAAA,EACjB,WAAW;AAAA,EACX,eAAe;AAAA,EACf,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,UAAU;AACZ;AAEA,MAAM,UAAU;AAAA,EACd,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,MAAM;AACR;AAEA,MAAM,cAAc;AAAA,EAClB,QAAQ;AAAA,EACR,OAAO;AACT;AAEA,MAAM,UAAU;AAAA,EACd,WAAW;AAAA,EACX,eAAe;AAAA,EACf,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,mBAAmB;AAAA,EACnB,0BAA0B;AAAA,EAC1B,eAAe;AAAA,EACf,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,eAAe;AAAA,EACf,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,aAAa;AAAA,EACb,cAAc;AAAA,EACd,UAAU;AACZ;AAEA,MAAM,eAAe;AAAA,EACnB,MAAM;AACR;AAEA,MAAM,cAAc;AAAA,EAClB,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,cAAc;AAAA;AAAA,EAEd,SAAS;AAAA,EACT,YAAY;AAAA;AAAA,EAEZ,YAAY;AACd;AAKO,MAAM,YAAY;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=global.d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/index.ts"],"sourcesContent":["export { useUser } from './useUser';\n"],"mappings":"AAAA,SAAS,eAAe;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { CabinIDContext } from "../client/provider";
|
|
4
|
+
const useUser = () => {
|
|
5
|
+
const useCabinIDContext = React.useContext(CabinIDContext);
|
|
6
|
+
if (!useCabinIDContext) {
|
|
7
|
+
throw new Error("Please wrap your app with CabinID Provider");
|
|
8
|
+
}
|
|
9
|
+
return useCabinIDContext.user;
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
useUser
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=useUser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/useUser.ts"],"sourcesContent":["'use client';\n\nimport React from 'react';\nimport { CabinIDContext } from '../client/provider';\n\nexport const useUser = () => {\n const useCabinIDContext = React.useContext(CabinIDContext);\n if (!useCabinIDContext) {\n throw new Error('Please wrap your app with CabinID Provider');\n }\n return useCabinIDContext.user;\n};\n"],"mappings":";AAEA,OAAO,WAAW;AAClB,SAAS,sBAAsB;AAExB,MAAM,UAAU,MAAM;AAC3B,QAAM,oBAAoB,MAAM,WAAW,cAAc;AACzD,MAAI,CAAC,mBAAmB;AACtB,UAAM,IAAI,MAAM,4CAA4C;AAAA,EAC9D;AACA,SAAO,kBAAkB;AAC3B;","names":[]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
const CabinLogo = (props) => /* @__PURE__ */ React.createElement(
|
|
3
|
+
"svg",
|
|
4
|
+
{
|
|
5
|
+
width: 24,
|
|
6
|
+
height: 25,
|
|
7
|
+
viewBox: "0 0 24 25",
|
|
8
|
+
fill: "none",
|
|
9
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
10
|
+
...props
|
|
11
|
+
},
|
|
12
|
+
/* @__PURE__ */ React.createElement("path", { d: "M24 12.816q0 12-12 12t-12-12 12-12 12 12", fill: "url(#a)" }),
|
|
13
|
+
/* @__PURE__ */ React.createElement(
|
|
14
|
+
"mask",
|
|
15
|
+
{
|
|
16
|
+
id: "c",
|
|
17
|
+
style: {
|
|
18
|
+
maskType: "alpha"
|
|
19
|
+
},
|
|
20
|
+
maskUnits: "userSpaceOnUse",
|
|
21
|
+
x: 0,
|
|
22
|
+
y: 0,
|
|
23
|
+
width: 24,
|
|
24
|
+
height: 25
|
|
25
|
+
},
|
|
26
|
+
/* @__PURE__ */ React.createElement("path", { d: "M24 12.816q0 12-12 12t-12-12 12-12 12 12", fill: "url(#b)" })
|
|
27
|
+
),
|
|
28
|
+
/* @__PURE__ */ React.createElement("g", { mask: "url(#c)" }, /* @__PURE__ */ React.createElement(
|
|
29
|
+
"path",
|
|
30
|
+
{
|
|
31
|
+
d: "M12.274 19.263q-2.97 0-4.853-1.79t-1.882-4.67q0-2.892 1.87-4.67 1.883-1.779 4.865-1.779 2.42 0 4.071 1.198t2.103 3.376l-3.252.35q-.281-1.089-1.051-1.633-.771-.544-1.907-.544-1.419 0-2.299 1.016t-.88 2.686q0 1.657.88 2.686.88 1.016 2.299 1.016 1.138 0 1.894-.544.77-.546 1.064-1.634l3.252.251c-.302 1.444-1.01 2.669-2.127 3.476q-1.663 1.21-4.047 1.21",
|
|
32
|
+
fill: "#1F5AF5"
|
|
33
|
+
}
|
|
34
|
+
)),
|
|
35
|
+
/* @__PURE__ */ React.createElement("defs", null, /* @__PURE__ */ React.createElement(
|
|
36
|
+
"linearGradient",
|
|
37
|
+
{
|
|
38
|
+
id: "a",
|
|
39
|
+
x1: 8.282,
|
|
40
|
+
y1: 15.013,
|
|
41
|
+
x2: 13.252,
|
|
42
|
+
y2: 30.181,
|
|
43
|
+
gradientUnits: "userSpaceOnUse"
|
|
44
|
+
},
|
|
45
|
+
/* @__PURE__ */ React.createElement("stop", { stopColor: "#fff" }),
|
|
46
|
+
/* @__PURE__ */ React.createElement("stop", { offset: 1, stopColor: "#fff", stopOpacity: 0 })
|
|
47
|
+
), /* @__PURE__ */ React.createElement(
|
|
48
|
+
"linearGradient",
|
|
49
|
+
{
|
|
50
|
+
id: "b",
|
|
51
|
+
x1: 8.282,
|
|
52
|
+
y1: 15.013,
|
|
53
|
+
x2: 13.252,
|
|
54
|
+
y2: 30.181,
|
|
55
|
+
gradientUnits: "userSpaceOnUse"
|
|
56
|
+
},
|
|
57
|
+
/* @__PURE__ */ React.createElement("stop", { stopColor: "#fff" }),
|
|
58
|
+
/* @__PURE__ */ React.createElement("stop", { offset: 1, stopColor: "#fff", stopOpacity: 0 })
|
|
59
|
+
))
|
|
60
|
+
);
|
|
61
|
+
export {
|
|
62
|
+
CabinLogo
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=logo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/icons/logo.tsx"],"sourcesContent":["import React from 'react';\n\nexport const CabinLogo: React.FC<React.SVGProps<SVGSVGElement>> = (props) => (\n <svg\n width={24}\n height={25}\n viewBox=\"0 0 24 25\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path d=\"M24 12.816q0 12-12 12t-12-12 12-12 12 12\" fill=\"url(#a)\" />\n <mask\n id=\"c\"\n style={{\n maskType: 'alpha',\n }}\n maskUnits=\"userSpaceOnUse\"\n x={0}\n y={0}\n width={24}\n height={25}\n >\n <path d=\"M24 12.816q0 12-12 12t-12-12 12-12 12 12\" fill=\"url(#b)\" />\n </mask>\n <g mask=\"url(#c)\">\n <path\n d=\"M12.274 19.263q-2.97 0-4.853-1.79t-1.882-4.67q0-2.892 1.87-4.67 1.883-1.779 4.865-1.779 2.42 0 4.071 1.198t2.103 3.376l-3.252.35q-.281-1.089-1.051-1.633-.771-.544-1.907-.544-1.419 0-2.299 1.016t-.88 2.686q0 1.657.88 2.686.88 1.016 2.299 1.016 1.138 0 1.894-.544.77-.546 1.064-1.634l3.252.251c-.302 1.444-1.01 2.669-2.127 3.476q-1.663 1.21-4.047 1.21\"\n fill=\"#1F5AF5\"\n />\n </g>\n <defs>\n <linearGradient\n id=\"a\"\n x1={8.282}\n y1={15.013}\n x2={13.252}\n y2={30.181}\n gradientUnits=\"userSpaceOnUse\"\n >\n <stop stopColor=\"#fff\" />\n <stop offset={1} stopColor=\"#fff\" stopOpacity={0} />\n </linearGradient>\n <linearGradient\n id=\"b\"\n x1={8.282}\n y1={15.013}\n x2={13.252}\n y2={30.181}\n gradientUnits=\"userSpaceOnUse\"\n >\n <stop stopColor=\"#fff\" />\n <stop offset={1} stopColor=\"#fff\" stopOpacity={0} />\n </linearGradient>\n </defs>\n </svg>\n);\n"],"mappings":"AAAA,OAAO,WAAW;AAEX,MAAM,YAAqD,CAAC,UACjE;AAAA,EAAC;AAAA;AAAA,IACC,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,SAAQ;AAAA,IACR,MAAK;AAAA,IACL,OAAM;AAAA,IACL,GAAG;AAAA;AAAA,EAEJ,oCAAC,UAAK,GAAE,4CAA2C,MAAK,WAAU;AAAA,EAClE;AAAA,IAAC;AAAA;AAAA,MACC,IAAG;AAAA,MACH,OAAO;AAAA,QACL,UAAU;AAAA,MACZ;AAAA,MACA,WAAU;AAAA,MACV,GAAG;AAAA,MACH,GAAG;AAAA,MACH,OAAO;AAAA,MACP,QAAQ;AAAA;AAAA,IAER,oCAAC,UAAK,GAAE,4CAA2C,MAAK,WAAU;AAAA,EACpE;AAAA,EACA,oCAAC,OAAE,MAAK,aACN;AAAA,IAAC;AAAA;AAAA,MACC,GAAE;AAAA,MACF,MAAK;AAAA;AAAA,EACP,CACF;AAAA,EACA,oCAAC,cACC;AAAA,IAAC;AAAA;AAAA,MACC,IAAG;AAAA,MACH,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,eAAc;AAAA;AAAA,IAEd,oCAAC,UAAK,WAAU,QAAO;AAAA,IACvB,oCAAC,UAAK,QAAQ,GAAG,WAAU,QAAO,aAAa,GAAG;AAAA,EACpD,GACA;AAAA,IAAC;AAAA;AAAA,MACC,IAAG;AAAA,MACH,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,eAAc;AAAA;AAAA,IAEd,oCAAC,UAAK,WAAU,QAAO;AAAA,IACvB,oCAAC,UAAK,QAAQ,GAAG,WAAU,QAAO,aAAa,GAAG;AAAA,EACpD,CACF;AACF;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { auth } from "./server/auth";
|
|
2
|
+
import { currentUser } from "./server/getCurrentUser";
|
|
3
|
+
import { CabinIDProvider } from "./client/provider";
|
|
4
|
+
import { useUser } from "./hooks";
|
|
5
|
+
import { authMiddleware } from "./server/middleware";
|
|
6
|
+
import { SignInButton } from "./components";
|
|
7
|
+
export {
|
|
8
|
+
CabinIDProvider,
|
|
9
|
+
SignInButton,
|
|
10
|
+
auth,
|
|
11
|
+
authMiddleware,
|
|
12
|
+
currentUser,
|
|
13
|
+
useUser
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["// import './styles/global.css';\n\nexport { auth } from './server/auth';\nexport { currentUser } from './server/getCurrentUser';\nexport { CabinIDProvider } from './client/provider';\nexport { useUser } from './hooks';\nexport { authMiddleware } from './server/middleware';\nexport { SignInButton } from './components';\n"],"mappings":"AAEA,SAAS,YAAY;AACrB,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import { cookies } from "next/headers";
|
|
3
|
+
import { constants } from "../constants";
|
|
4
|
+
const auth = () => {
|
|
5
|
+
var _a;
|
|
6
|
+
const cookie = cookies();
|
|
7
|
+
const userId = ((_a = cookie.get(constants.Cookies.User)) == null ? void 0 : _a.value) || null;
|
|
8
|
+
return { userId };
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
auth
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/auth.ts"],"sourcesContent":["'use server';\n\nimport { cookies } from 'next/headers';\nimport { constants } from '../constants';\n\nexport const auth = () => {\n const cookie = cookies();\n const userId = cookie.get(constants.Cookies.User)?.value || null;\n\n return { userId };\n};\n"],"mappings":";AAEA,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAEnB,MAAM,OAAO,MAAM;AAL1B;AAME,QAAM,SAAS,QAAQ;AACvB,QAAM,WAAS,YAAO,IAAI,UAAU,QAAQ,IAAI,MAAjC,mBAAoC,UAAS;AAE5D,SAAO,EAAE,OAAO;AAClB;","names":[]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { parsePublishableKey } from "../utils/key";
|
|
2
|
+
const buildUrl = (_baseUrl, _targetUrl, _returnBackUrl) => {
|
|
3
|
+
if (_baseUrl === "") {
|
|
4
|
+
const legacyUrl = legacyBuildUrl(
|
|
5
|
+
_targetUrl.toString(),
|
|
6
|
+
_returnBackUrl == null ? void 0 : _returnBackUrl.toString()
|
|
7
|
+
);
|
|
8
|
+
return legacyUrl;
|
|
9
|
+
}
|
|
10
|
+
const baseUrl = new URL(_baseUrl);
|
|
11
|
+
const returnBackUrl = _returnBackUrl ? new URL(_returnBackUrl, baseUrl) : void 0;
|
|
12
|
+
const res = new URL(_targetUrl, baseUrl);
|
|
13
|
+
if (returnBackUrl) {
|
|
14
|
+
res.searchParams.set("redirect_url", returnBackUrl.toString());
|
|
15
|
+
}
|
|
16
|
+
return res.toString();
|
|
17
|
+
};
|
|
18
|
+
const legacyBuildUrl = (targetUrl, redirectUrl) => {
|
|
19
|
+
let url;
|
|
20
|
+
if (!targetUrl.startsWith("http")) {
|
|
21
|
+
if (!redirectUrl || !redirectUrl.startsWith("http")) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
"destination url or return back url should be an absolute path url!"
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
const baseURL = new URL(redirectUrl);
|
|
27
|
+
url = new URL(targetUrl, baseURL.origin);
|
|
28
|
+
} else {
|
|
29
|
+
url = new URL(targetUrl);
|
|
30
|
+
}
|
|
31
|
+
if (redirectUrl) {
|
|
32
|
+
url.searchParams.set("redirect_url", redirectUrl);
|
|
33
|
+
}
|
|
34
|
+
return url.toString();
|
|
35
|
+
};
|
|
36
|
+
const createRedirect = (params) => {
|
|
37
|
+
const { publishableKey, redirectAdapter, signInUrl, signUpUrl, baseUrl } = params;
|
|
38
|
+
const frontendApi = parsePublishableKey(publishableKey);
|
|
39
|
+
const accountsBaseUrl = frontendApi;
|
|
40
|
+
const redirectToSignUp = ({ returnBackUrl } = {}) => {
|
|
41
|
+
if (!signUpUrl && !accountsBaseUrl) {
|
|
42
|
+
throw new Error("Publish Key is not exist");
|
|
43
|
+
}
|
|
44
|
+
const accountsSignUpUrl = `${accountsBaseUrl}/sign-up`;
|
|
45
|
+
const redirect = redirectAdapter(
|
|
46
|
+
buildUrl(baseUrl, signUpUrl || accountsSignUpUrl, returnBackUrl)
|
|
47
|
+
);
|
|
48
|
+
return redirect;
|
|
49
|
+
};
|
|
50
|
+
const redirectToSignIn = ({ returnBackUrl } = {}) => {
|
|
51
|
+
if (!signInUrl && !accountsBaseUrl) {
|
|
52
|
+
throw new Error("Publish Key is not exist");
|
|
53
|
+
}
|
|
54
|
+
const accountsSignInUrl = `${accountsBaseUrl}/sign-in`;
|
|
55
|
+
const redirect = redirectAdapter(
|
|
56
|
+
buildUrl(baseUrl, signInUrl || accountsSignInUrl, returnBackUrl)
|
|
57
|
+
);
|
|
58
|
+
return redirect;
|
|
59
|
+
};
|
|
60
|
+
return { redirectToSignUp, redirectToSignIn };
|
|
61
|
+
};
|
|
62
|
+
export {
|
|
63
|
+
createRedirect
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=createRedirect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/createRedirect.ts"],"sourcesContent":["import { parsePublishableKey } from '../utils/key';\n\ntype RedirectAdapter<RedirectReturn> = (url: string) => RedirectReturn;\ntype RedirectToParams = { returnBackUrl?: string | URL | null };\nexport type RedirectFun<ReturnType> = (params?: RedirectToParams) => ReturnType;\n\nconst buildUrl = (\n _baseUrl: string | URL,\n _targetUrl: string | URL,\n _returnBackUrl?: string | URL | null\n) => {\n if (_baseUrl === '') {\n const legacyUrl = legacyBuildUrl(\n _targetUrl.toString(),\n _returnBackUrl?.toString()\n );\n return legacyUrl;\n }\n\n const baseUrl = new URL(_baseUrl);\n const returnBackUrl = _returnBackUrl\n ? new URL(_returnBackUrl, baseUrl)\n : undefined;\n const res = new URL(_targetUrl, baseUrl);\n\n if (returnBackUrl) {\n res.searchParams.set('redirect_url', returnBackUrl.toString());\n }\n return res.toString();\n};\n\nconst legacyBuildUrl = (targetUrl: string, redirectUrl?: string) => {\n let url;\n if (!targetUrl.startsWith('http')) {\n if (!redirectUrl || !redirectUrl.startsWith('http')) {\n throw new Error(\n 'destination url or return back url should be an absolute path url!'\n );\n }\n\n const baseURL = new URL(redirectUrl);\n url = new URL(targetUrl, baseURL.origin);\n } else {\n url = new URL(targetUrl);\n }\n\n if (redirectUrl) {\n url.searchParams.set('redirect_url', redirectUrl);\n }\n\n return url.toString();\n};\n\n/**\n * @internal\n */\ntype CreateRedirect = <ReturnType>(params: {\n publishableKey: string;\n redirectAdapter: RedirectAdapter<ReturnType>;\n baseUrl: URL | string;\n signInUrl?: URL | string;\n signUpUrl?: URL | string;\n}) => {\n redirectToSignIn: RedirectFun<ReturnType>;\n redirectToSignUp: RedirectFun<ReturnType>;\n};\n\nexport const createRedirect: CreateRedirect = (params) => {\n const { publishableKey, redirectAdapter, signInUrl, signUpUrl, baseUrl } =\n params;\n const frontendApi = parsePublishableKey(publishableKey);\n const accountsBaseUrl = frontendApi;\n\n const redirectToSignUp = ({ returnBackUrl }: RedirectToParams = {}) => {\n if (!signUpUrl && !accountsBaseUrl) {\n throw new Error('Publish Key is not exist');\n }\n const accountsSignUpUrl = `${accountsBaseUrl}/sign-up`;\n const redirect = redirectAdapter(\n buildUrl(baseUrl, signUpUrl || accountsSignUpUrl, returnBackUrl)\n );\n return redirect;\n };\n\n const redirectToSignIn = ({ returnBackUrl }: RedirectToParams = {}) => {\n if (!signInUrl && !accountsBaseUrl) {\n throw new Error('Publish Key is not exist');\n }\n const accountsSignInUrl = `${accountsBaseUrl}/sign-in`;\n\n const redirect = redirectAdapter(\n buildUrl(baseUrl, signInUrl || accountsSignInUrl, returnBackUrl)\n );\n\n return redirect;\n };\n\n return { redirectToSignUp, redirectToSignIn };\n};\n"],"mappings":"AAAA,SAAS,2BAA2B;AAMpC,MAAM,WAAW,CACf,UACA,YACA,mBACG;AACH,MAAI,aAAa,IAAI;AACnB,UAAM,YAAY;AAAA,MAChB,WAAW,SAAS;AAAA,MACpB,iDAAgB;AAAA,IAClB;AACA,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,IAAI,IAAI,QAAQ;AAChC,QAAM,gBAAgB,iBAClB,IAAI,IAAI,gBAAgB,OAAO,IAC/B;AACJ,QAAM,MAAM,IAAI,IAAI,YAAY,OAAO;AAEvC,MAAI,eAAe;AACjB,QAAI,aAAa,IAAI,gBAAgB,cAAc,SAAS,CAAC;AAAA,EAC/D;AACA,SAAO,IAAI,SAAS;AACtB;AAEA,MAAM,iBAAiB,CAAC,WAAmB,gBAAyB;AAClE,MAAI;AACJ,MAAI,CAAC,UAAU,WAAW,MAAM,GAAG;AACjC,QAAI,CAAC,eAAe,CAAC,YAAY,WAAW,MAAM,GAAG;AACnD,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,UAAU,IAAI,IAAI,WAAW;AACnC,UAAM,IAAI,IAAI,WAAW,QAAQ,MAAM;AAAA,EACzC,OAAO;AACL,UAAM,IAAI,IAAI,SAAS;AAAA,EACzB;AAEA,MAAI,aAAa;AACf,QAAI,aAAa,IAAI,gBAAgB,WAAW;AAAA,EAClD;AAEA,SAAO,IAAI,SAAS;AACtB;AAgBO,MAAM,iBAAiC,CAAC,WAAW;AACxD,QAAM,EAAE,gBAAgB,iBAAiB,WAAW,WAAW,QAAQ,IACrE;AACF,QAAM,cAAc,oBAAoB,cAAc;AACtD,QAAM,kBAAkB;AAExB,QAAM,mBAAmB,CAAC,EAAE,cAAc,IAAsB,CAAC,MAAM;AACrE,QAAI,CAAC,aAAa,CAAC,iBAAiB;AAClC,YAAM,IAAI,MAAM,0BAA0B;AAAA,IAC5C;AACA,UAAM,oBAAoB,GAAG,eAAe;AAC5C,UAAM,WAAW;AAAA,MACf,SAAS,SAAS,aAAa,mBAAmB,aAAa;AAAA,IACjE;AACA,WAAO;AAAA,EACT;AAEA,QAAM,mBAAmB,CAAC,EAAE,cAAc,IAAsB,CAAC,MAAM;AACrE,QAAI,CAAC,aAAa,CAAC,iBAAiB;AAClC,YAAM,IAAI,MAAM,0BAA0B;AAAA,IAC5C;AACA,UAAM,oBAAoB,GAAG,eAAe;AAE5C,UAAM,WAAW;AAAA,MACf,SAAS,SAAS,aAAa,mBAAmB,aAAa;AAAA,IACjE;AAEA,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,kBAAkB,iBAAiB;AAC9C;","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { baseApiUrl, SECRET_KEY } from "../constants";
|
|
2
|
+
import { auth } from "./auth";
|
|
3
|
+
async function currentUser() {
|
|
4
|
+
const { userId } = auth();
|
|
5
|
+
if (!userId)
|
|
6
|
+
return null;
|
|
7
|
+
const response = await fetch(`${baseApiUrl}/user/${userId}`, {
|
|
8
|
+
method: "GET",
|
|
9
|
+
headers: {
|
|
10
|
+
Authorization: `Bearer ${SECRET_KEY}`
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
const data = await response.json();
|
|
14
|
+
return data;
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
currentUser
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=getCurrentUser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/getCurrentUser.ts"],"sourcesContent":["import { baseApiUrl, SECRET_KEY } from '../constants';\n\nimport { auth } from './auth';\n\nexport type User = {\n id: string;\n avatar: string | null;\n email: string | null;\n phoneNumber: string;\n firstName: string;\n lastName: string;\n address: string | null;\n createdAt: string;\n updatedAt: string;\n};\n\nexport async function currentUser(): Promise<User | null> {\n const { userId } = auth();\n if (!userId) return null;\n\n const response = await fetch(`${baseApiUrl}/user/${userId}`, {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${SECRET_KEY}`,\n },\n });\n const data: User = await response.json();\n return data;\n}\n"],"mappings":"AAAA,SAAS,YAAY,kBAAkB;AAEvC,SAAS,YAAY;AAcrB,eAAsB,cAAoC;AACxD,QAAM,EAAE,OAAO,IAAI,KAAK;AACxB,MAAI,CAAC;AAAQ,WAAO;AAEpB,QAAM,WAAW,MAAM,MAAM,GAAG,UAAU,SAAS,MAAM,IAAI;AAAA,IAC3D,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,eAAe,UAAU,UAAU;AAAA,IACrC;AAAA,EACF,CAAC;AACD,QAAM,OAAa,MAAM,SAAS,KAAK;AACvC,SAAO;AACT;","names":[]}
|