@ory/elements-react 1.0.0-next.9 → 1.0.0-pr.6c5e72b6
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/CHANGELOG.md +601 -0
- package/DEVELOPMENT.md +95 -0
- package/LICENSE +201 -0
- package/README.md +359 -32
- package/babel.config.js +10 -0
- package/dist/client/config.d.mts +21 -0
- package/dist/client/config.d.ts +21 -0
- package/dist/client/config.js +77 -0
- package/dist/client/config.js.map +1 -0
- package/dist/client/config.mjs +51 -0
- package/dist/client/config.mjs.map +1 -0
- package/dist/client/frontendClient.d.mts +10 -0
- package/dist/client/frontendClient.d.ts +10 -0
- package/dist/client/frontendClient.js +75 -0
- package/dist/client/frontendClient.js.map +1 -0
- package/dist/client/frontendClient.mjs +54 -0
- package/dist/client/frontendClient.mjs.map +1 -0
- package/dist/client/index.d.mts +5 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.js +33 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/index.mjs +10 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/client/session-provider.d.mts +62 -0
- package/dist/client/session-provider.d.ts +62 -0
- package/dist/client/session-provider.js +96 -0
- package/dist/client/session-provider.js.map +1 -0
- package/dist/client/session-provider.mjs +71 -0
- package/dist/client/session-provider.mjs.map +1 -0
- package/dist/client/useSession.d.mts +32 -0
- package/dist/client/useSession.d.ts +32 -0
- package/dist/client/useSession.js +37 -0
- package/dist/client/useSession.js.map +1 -0
- package/dist/client/useSession.mjs +13 -0
- package/dist/client/useSession.mjs.map +1 -0
- package/dist/index.d.mts +531 -1888
- package/dist/index.d.ts +531 -1888
- package/dist/index.js +4335 -2566
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4329 -2552
- package/dist/index.mjs.map +1 -1
- package/dist/theme/default/index.css +995 -308
- package/dist/theme/default/index.css.map +1 -1
- package/dist/theme/default/index.d.mts +54 -15
- package/dist/theme/default/index.d.ts +54 -15
- package/dist/theme/default/index.js +5745 -784
- package/dist/theme/default/index.js.map +1 -1
- package/dist/theme/default/index.mjs +5847 -770
- package/dist/theme/default/index.mjs.map +1 -1
- package/dist/theme/default/tailwind/defaults.d.mts +737 -0
- package/dist/theme/default/tailwind/defaults.d.ts +737 -0
- package/dist/theme/default/tailwind/defaults.js +219 -0
- package/dist/theme/default/tailwind/defaults.js.map +1 -0
- package/dist/theme/default/tailwind/defaults.mjs +196 -0
- package/dist/theme/default/tailwind/defaults.mjs.map +1 -0
- package/package.json +39 -14
- package/tailwind/defaults.ts +34 -0
- package/tailwind/generated/README.md +2 -0
- package/tailwind/generated/default-variables.css +216 -0
- package/tailwind/generated/variables-processed.json +161 -0
- package/tsconfig.json +10 -9
- package/tsconfig.runtime.json +4 -0
- package/.eslintrc.js +0 -61
- package/.vscode/i18n-ally-reviews.yml +0 -3
- package/.vscode/settings.json +0 -4
- package/api-report/elements-react-theme.api.json +0 -1260
- package/api-report/elements-react-theme.api.md +0 -128
- package/api-report/elements-react.api.json +0 -4262
- package/api-report/elements-react.api.md +0 -393
- package/api-report/temp/elements-react-theme.api.md +0 -130
- package/api-report/temp/elements-react.api.md +0 -328
- package/config/api-extractor-core.json +0 -457
- package/config/api-extractor-theme.json +0 -463
- package/jest.config.ts +0 -16
- package/postcss.config.ts +0 -6
- package/tailwind.config.ts +0 -54
- package/tsconfig.spec.json +0 -20
- package/variables-processed.json +0 -193
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function returns the base URL of the Ory SDK as set by environment variables `NEXT_PUBLIC_ORY_SDK_URL` or `ORY_SDK_URL`.
|
|
3
|
+
*/
|
|
4
|
+
declare function orySdkUrl(): string;
|
|
5
|
+
/**
|
|
6
|
+
* This function returns whether the current environment is a production environment.
|
|
7
|
+
*/
|
|
8
|
+
declare function isProduction(): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* This function returns the Ory SDK URL. If the environment is not production, it tries to guess the SDK URL based on the environment variables, assuming
|
|
11
|
+
* that Ory APIs are proxied through the same domain as the application.
|
|
12
|
+
*
|
|
13
|
+
* Currently, this is only tested for Vercel deployments.
|
|
14
|
+
*
|
|
15
|
+
* @param options - Options for guessing the SDK URL.
|
|
16
|
+
*/
|
|
17
|
+
declare function guessPotentiallyProxiedOrySdkUrl(options?: {
|
|
18
|
+
knownProxiedUrl?: string;
|
|
19
|
+
}): string;
|
|
20
|
+
|
|
21
|
+
export { guessPotentiallyProxiedOrySdkUrl, isProduction, orySdkUrl };
|
|
@@ -0,0 +1,77 @@
|
|
|
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 config_exports = {};
|
|
20
|
+
__export(config_exports, {
|
|
21
|
+
guessPotentiallyProxiedOrySdkUrl: () => guessPotentiallyProxiedOrySdkUrl,
|
|
22
|
+
isProduction: () => isProduction,
|
|
23
|
+
orySdkUrl: () => orySdkUrl
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(config_exports);
|
|
26
|
+
function orySdkUrl() {
|
|
27
|
+
let baseUrl;
|
|
28
|
+
if (process.env.NEXT_PUBLIC_ORY_SDK_URL) {
|
|
29
|
+
baseUrl = process.env.NEXT_PUBLIC_ORY_SDK_URL;
|
|
30
|
+
}
|
|
31
|
+
if (process.env.ORY_SDK_URL) {
|
|
32
|
+
baseUrl = process.env._ORY_SDK_URL;
|
|
33
|
+
}
|
|
34
|
+
if (!baseUrl) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
"You need to set environment variable `NEXT_PUBLIC_ORY_SDK_URL` or if you don't use Next.js `ORY_SDK_URL` to your Ory Network SDK URL."
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return baseUrl.replace(/\/$/, "");
|
|
40
|
+
}
|
|
41
|
+
function isProduction() {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
return ["production", "prod"].indexOf(
|
|
44
|
+
(_b = (_a = process.env.VERCEL_ENV) != null ? _a : process.env.NODE_ENV) != null ? _b : ""
|
|
45
|
+
) > -1;
|
|
46
|
+
}
|
|
47
|
+
function guessPotentiallyProxiedOrySdkUrl(options) {
|
|
48
|
+
if (isProduction()) {
|
|
49
|
+
return orySdkUrl();
|
|
50
|
+
}
|
|
51
|
+
if (process.env.VERCEL_ENV) {
|
|
52
|
+
if (!isProduction() && process.env.VERCEL_URL) {
|
|
53
|
+
return `https://${process.env.VERCEL_URL}`.replace(/\/$/, "");
|
|
54
|
+
}
|
|
55
|
+
if (process.env.__NEXT_PRIVATE_ORIGIN) {
|
|
56
|
+
return process.env.__NEXT_PRIVATE_ORIGIN.replace(/\/$/, "");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (typeof window !== "undefined") {
|
|
60
|
+
return window.location.origin;
|
|
61
|
+
}
|
|
62
|
+
if (options == null ? void 0 : options.knownProxiedUrl) {
|
|
63
|
+
return options.knownProxiedUrl;
|
|
64
|
+
}
|
|
65
|
+
const final = orySdkUrl();
|
|
66
|
+
console.warn(
|
|
67
|
+
`Unable to determine a suitable SDK URL for setting up the Next.js integration of Ory Elements. Will proceed using default Ory SDK URL "${final}". This is likely not what you want for local development and your authentication and login may not work.`
|
|
68
|
+
);
|
|
69
|
+
return final;
|
|
70
|
+
}
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
guessPotentiallyProxiedOrySdkUrl,
|
|
74
|
+
isProduction,
|
|
75
|
+
orySdkUrl
|
|
76
|
+
});
|
|
77
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/config.ts"],"sourcesContent":["// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * This function returns the base URL of the Ory SDK as set by environment variables `NEXT_PUBLIC_ORY_SDK_URL` or `ORY_SDK_URL`.\n */\nexport function orySdkUrl() {\n let baseUrl\n\n if (process.env.NEXT_PUBLIC_ORY_SDK_URL) {\n baseUrl = process.env.NEXT_PUBLIC_ORY_SDK_URL\n }\n\n if (process.env.ORY_SDK_URL) {\n baseUrl = process.env._ORY_SDK_URL\n }\n\n if (!baseUrl) {\n throw new Error(\n \"You need to set environment variable `NEXT_PUBLIC_ORY_SDK_URL` or if you don't use Next.js `ORY_SDK_URL` to your Ory Network SDK URL.\",\n )\n }\n\n return baseUrl.replace(/\\/$/, \"\")\n}\n\n/**\n * This function returns whether the current environment is a production environment.\n */\nexport function isProduction() {\n return (\n [\"production\", \"prod\"].indexOf(\n process.env.VERCEL_ENV ?? process.env.NODE_ENV ?? \"\",\n ) > -1\n )\n}\n\n/**\n * This function returns the Ory SDK URL. If the environment is not production, it tries to guess the SDK URL based on the environment variables, assuming\n * that Ory APIs are proxied through the same domain as the application.\n *\n * Currently, this is only tested for Vercel deployments.\n *\n * @param options - Options for guessing the SDK URL.\n */\nexport function guessPotentiallyProxiedOrySdkUrl(options?: {\n knownProxiedUrl?: string\n}) {\n if (isProduction()) {\n // In production, we use the production custom domain\n return orySdkUrl()\n }\n\n if (process.env.VERCEL_ENV) {\n // We are in vercel\n\n // The domain name of the generated deployment URL. Example: *.vercel.app. The value does not include the protocol scheme https://.\n //\n // This is only available for preview deployments on Vercel.\n if (!isProduction() && process.env.VERCEL_URL) {\n return `https://${process.env.VERCEL_URL}`.replace(/\\/$/, \"\")\n }\n\n // This is sometimes set by the render server.\n if (process.env.__NEXT_PRIVATE_ORIGIN) {\n return process.env.__NEXT_PRIVATE_ORIGIN.replace(/\\/$/, \"\")\n }\n }\n\n // Unable to figure out the SDK URL. Either because we are not using Vercel or because we are on a local machine.\n // Let's try to use the window location.\n if (typeof window !== \"undefined\") {\n return window.location.origin\n }\n\n if (options?.knownProxiedUrl) {\n return options.knownProxiedUrl\n }\n\n // We tried everything. Let's use the SDK URL.\n const final = orySdkUrl()\n console.warn(\n `Unable to determine a suitable SDK URL for setting up the Next.js integration of Ory Elements. Will proceed using default Ory SDK URL \"${final}\". This is likely not what you want for local development and your authentication and login may not work.`,\n )\n\n return final\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,SAAS,YAAY;AAC1B,MAAI;AAEJ,MAAI,QAAQ,IAAI,yBAAyB;AACvC,cAAU,QAAQ,IAAI;AAAA,EACxB;AAEA,MAAI,QAAQ,IAAI,aAAa;AAC3B,cAAU,QAAQ,IAAI;AAAA,EACxB;AAEA,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,QAAQ,QAAQ,OAAO,EAAE;AAClC;AAKO,SAAS,eAAe;AA7B/B;AA8BE,SACE,CAAC,cAAc,MAAM,EAAE;AAAA,KACrB,mBAAQ,IAAI,eAAZ,YAA0B,QAAQ,IAAI,aAAtC,YAAkD;AAAA,EACpD,IAAI;AAER;AAUO,SAAS,iCAAiC,SAE9C;AACD,MAAI,aAAa,GAAG;AAElB,WAAO,UAAU;AAAA,EACnB;AAEA,MAAI,QAAQ,IAAI,YAAY;AAM1B,QAAI,CAAC,aAAa,KAAK,QAAQ,IAAI,YAAY;AAC7C,aAAO,WAAW,QAAQ,IAAI,UAAU,GAAG,QAAQ,OAAO,EAAE;AAAA,IAC9D;AAGA,QAAI,QAAQ,IAAI,uBAAuB;AACrC,aAAO,QAAQ,IAAI,sBAAsB,QAAQ,OAAO,EAAE;AAAA,IAC5D;AAAA,EACF;AAIA,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO,OAAO,SAAS;AAAA,EACzB;AAEA,MAAI,mCAAS,iBAAiB;AAC5B,WAAO,QAAQ;AAAA,EACjB;AAGA,QAAM,QAAQ,UAAU;AACxB,UAAQ;AAAA,IACN,0IAA0I,KAAK;AAAA,EACjJ;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
function orySdkUrl() {
|
|
2
|
+
let baseUrl;
|
|
3
|
+
if (process.env.NEXT_PUBLIC_ORY_SDK_URL) {
|
|
4
|
+
baseUrl = process.env.NEXT_PUBLIC_ORY_SDK_URL;
|
|
5
|
+
}
|
|
6
|
+
if (process.env.ORY_SDK_URL) {
|
|
7
|
+
baseUrl = process.env._ORY_SDK_URL;
|
|
8
|
+
}
|
|
9
|
+
if (!baseUrl) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
"You need to set environment variable `NEXT_PUBLIC_ORY_SDK_URL` or if you don't use Next.js `ORY_SDK_URL` to your Ory Network SDK URL."
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
return baseUrl.replace(/\/$/, "");
|
|
15
|
+
}
|
|
16
|
+
function isProduction() {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
return ["production", "prod"].indexOf(
|
|
19
|
+
(_b = (_a = process.env.VERCEL_ENV) != null ? _a : process.env.NODE_ENV) != null ? _b : ""
|
|
20
|
+
) > -1;
|
|
21
|
+
}
|
|
22
|
+
function guessPotentiallyProxiedOrySdkUrl(options) {
|
|
23
|
+
if (isProduction()) {
|
|
24
|
+
return orySdkUrl();
|
|
25
|
+
}
|
|
26
|
+
if (process.env.VERCEL_ENV) {
|
|
27
|
+
if (!isProduction() && process.env.VERCEL_URL) {
|
|
28
|
+
return `https://${process.env.VERCEL_URL}`.replace(/\/$/, "");
|
|
29
|
+
}
|
|
30
|
+
if (process.env.__NEXT_PRIVATE_ORIGIN) {
|
|
31
|
+
return process.env.__NEXT_PRIVATE_ORIGIN.replace(/\/$/, "");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (typeof window !== "undefined") {
|
|
35
|
+
return window.location.origin;
|
|
36
|
+
}
|
|
37
|
+
if (options == null ? void 0 : options.knownProxiedUrl) {
|
|
38
|
+
return options.knownProxiedUrl;
|
|
39
|
+
}
|
|
40
|
+
const final = orySdkUrl();
|
|
41
|
+
console.warn(
|
|
42
|
+
`Unable to determine a suitable SDK URL for setting up the Next.js integration of Ory Elements. Will proceed using default Ory SDK URL "${final}". This is likely not what you want for local development and your authentication and login may not work.`
|
|
43
|
+
);
|
|
44
|
+
return final;
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
guessPotentiallyProxiedOrySdkUrl,
|
|
48
|
+
isProduction,
|
|
49
|
+
orySdkUrl
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=config.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/config.ts"],"sourcesContent":["// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * This function returns the base URL of the Ory SDK as set by environment variables `NEXT_PUBLIC_ORY_SDK_URL` or `ORY_SDK_URL`.\n */\nexport function orySdkUrl() {\n let baseUrl\n\n if (process.env.NEXT_PUBLIC_ORY_SDK_URL) {\n baseUrl = process.env.NEXT_PUBLIC_ORY_SDK_URL\n }\n\n if (process.env.ORY_SDK_URL) {\n baseUrl = process.env._ORY_SDK_URL\n }\n\n if (!baseUrl) {\n throw new Error(\n \"You need to set environment variable `NEXT_PUBLIC_ORY_SDK_URL` or if you don't use Next.js `ORY_SDK_URL` to your Ory Network SDK URL.\",\n )\n }\n\n return baseUrl.replace(/\\/$/, \"\")\n}\n\n/**\n * This function returns whether the current environment is a production environment.\n */\nexport function isProduction() {\n return (\n [\"production\", \"prod\"].indexOf(\n process.env.VERCEL_ENV ?? process.env.NODE_ENV ?? \"\",\n ) > -1\n )\n}\n\n/**\n * This function returns the Ory SDK URL. If the environment is not production, it tries to guess the SDK URL based on the environment variables, assuming\n * that Ory APIs are proxied through the same domain as the application.\n *\n * Currently, this is only tested for Vercel deployments.\n *\n * @param options - Options for guessing the SDK URL.\n */\nexport function guessPotentiallyProxiedOrySdkUrl(options?: {\n knownProxiedUrl?: string\n}) {\n if (isProduction()) {\n // In production, we use the production custom domain\n return orySdkUrl()\n }\n\n if (process.env.VERCEL_ENV) {\n // We are in vercel\n\n // The domain name of the generated deployment URL. Example: *.vercel.app. The value does not include the protocol scheme https://.\n //\n // This is only available for preview deployments on Vercel.\n if (!isProduction() && process.env.VERCEL_URL) {\n return `https://${process.env.VERCEL_URL}`.replace(/\\/$/, \"\")\n }\n\n // This is sometimes set by the render server.\n if (process.env.__NEXT_PRIVATE_ORIGIN) {\n return process.env.__NEXT_PRIVATE_ORIGIN.replace(/\\/$/, \"\")\n }\n }\n\n // Unable to figure out the SDK URL. Either because we are not using Vercel or because we are on a local machine.\n // Let's try to use the window location.\n if (typeof window !== \"undefined\") {\n return window.location.origin\n }\n\n if (options?.knownProxiedUrl) {\n return options.knownProxiedUrl\n }\n\n // We tried everything. Let's use the SDK URL.\n const final = orySdkUrl()\n console.warn(\n `Unable to determine a suitable SDK URL for setting up the Next.js integration of Ory Elements. Will proceed using default Ory SDK URL \"${final}\". This is likely not what you want for local development and your authentication and login may not work.`,\n )\n\n return final\n}\n"],"mappings":"AAMO,SAAS,YAAY;AAC1B,MAAI;AAEJ,MAAI,QAAQ,IAAI,yBAAyB;AACvC,cAAU,QAAQ,IAAI;AAAA,EACxB;AAEA,MAAI,QAAQ,IAAI,aAAa;AAC3B,cAAU,QAAQ,IAAI;AAAA,EACxB;AAEA,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,QAAQ,QAAQ,OAAO,EAAE;AAClC;AAKO,SAAS,eAAe;AA7B/B;AA8BE,SACE,CAAC,cAAc,MAAM,EAAE;AAAA,KACrB,mBAAQ,IAAI,eAAZ,YAA0B,QAAQ,IAAI,aAAtC,YAAkD;AAAA,EACpD,IAAI;AAER;AAUO,SAAS,iCAAiC,SAE9C;AACD,MAAI,aAAa,GAAG;AAElB,WAAO,UAAU;AAAA,EACnB;AAEA,MAAI,QAAQ,IAAI,YAAY;AAM1B,QAAI,CAAC,aAAa,KAAK,QAAQ,IAAI,YAAY;AAC7C,aAAO,WAAW,QAAQ,IAAI,UAAU,GAAG,QAAQ,OAAO,EAAE;AAAA,IAC9D;AAGA,QAAI,QAAQ,IAAI,uBAAuB;AACrC,aAAO,QAAQ,IAAI,sBAAsB,QAAQ,OAAO,EAAE;AAAA,IAC5D;AAAA,EACF;AAIA,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO,OAAO,SAAS;AAAA,EACzB;AAEA,MAAI,mCAAS,iBAAiB;AAC5B,WAAO,QAAQ;AAAA,EACjB;AAGA,QAAM,QAAQ,UAAU;AACxB,UAAQ;AAAA,IACN,0IAA0I,KAAK;AAAA,EACjJ;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ConfigurationParameters, FrontendApi, OAuth2Api } from '@ory/client-fetch';
|
|
2
|
+
|
|
3
|
+
declare function frontendClient({ forceBaseUrl, ...opts }?: Partial<ConfigurationParameters & {
|
|
4
|
+
forceBaseUrl?: string;
|
|
5
|
+
}>): FrontendApi;
|
|
6
|
+
declare function oauth2Client({ forceBaseUrl, ...opts }?: Partial<ConfigurationParameters & {
|
|
7
|
+
forceBaseUrl?: string;
|
|
8
|
+
}>): OAuth2Api;
|
|
9
|
+
|
|
10
|
+
export { frontendClient, oauth2Client };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ConfigurationParameters, FrontendApi, OAuth2Api } from '@ory/client-fetch';
|
|
2
|
+
|
|
3
|
+
declare function frontendClient({ forceBaseUrl, ...opts }?: Partial<ConfigurationParameters & {
|
|
4
|
+
forceBaseUrl?: string;
|
|
5
|
+
}>): FrontendApi;
|
|
6
|
+
declare function oauth2Client({ forceBaseUrl, ...opts }?: Partial<ConfigurationParameters & {
|
|
7
|
+
forceBaseUrl?: string;
|
|
8
|
+
}>): OAuth2Api;
|
|
9
|
+
|
|
10
|
+
export { frontendClient, oauth2Client };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var frontendClient_exports = {};
|
|
21
|
+
__export(frontendClient_exports, {
|
|
22
|
+
frontendClient: () => frontendClient,
|
|
23
|
+
oauth2Client: () => oauth2Client
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(frontendClient_exports);
|
|
26
|
+
var import_client_fetch = require("@ory/client-fetch");
|
|
27
|
+
var import_config = require("./config");
|
|
28
|
+
function frontendClient({
|
|
29
|
+
forceBaseUrl,
|
|
30
|
+
...opts
|
|
31
|
+
} = {
|
|
32
|
+
credentials: "include"
|
|
33
|
+
}) {
|
|
34
|
+
var _a;
|
|
35
|
+
const basePath = forceBaseUrl != null ? forceBaseUrl : (0, import_config.guessPotentiallyProxiedOrySdkUrl)({
|
|
36
|
+
knownProxiedUrl: window.location.origin
|
|
37
|
+
});
|
|
38
|
+
const config = new import_client_fetch.Configuration({
|
|
39
|
+
...opts,
|
|
40
|
+
basePath: basePath == null ? void 0 : basePath.replace(/\/$/, ""),
|
|
41
|
+
credentials: (_a = opts.credentials) != null ? _a : "include",
|
|
42
|
+
headers: {
|
|
43
|
+
Accept: "application/json",
|
|
44
|
+
...opts.headers
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return new import_client_fetch.FrontendApi(config);
|
|
48
|
+
}
|
|
49
|
+
function oauth2Client({
|
|
50
|
+
forceBaseUrl,
|
|
51
|
+
...opts
|
|
52
|
+
} = {
|
|
53
|
+
credentials: "include"
|
|
54
|
+
}) {
|
|
55
|
+
var _a;
|
|
56
|
+
const basePath = forceBaseUrl != null ? forceBaseUrl : (0, import_config.guessPotentiallyProxiedOrySdkUrl)({
|
|
57
|
+
knownProxiedUrl: window.location.origin
|
|
58
|
+
});
|
|
59
|
+
const config = new import_client_fetch.Configuration({
|
|
60
|
+
...opts,
|
|
61
|
+
basePath: basePath == null ? void 0 : basePath.replace(/\/$/, ""),
|
|
62
|
+
credentials: (_a = opts.credentials) != null ? _a : "include",
|
|
63
|
+
headers: {
|
|
64
|
+
Accept: "application/json",
|
|
65
|
+
...opts.headers
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return new import_client_fetch.OAuth2Api(config);
|
|
69
|
+
}
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
frontendClient,
|
|
73
|
+
oauth2Client
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=frontendClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/frontendClient.ts"],"sourcesContent":["// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\"use client\"\nimport {\n Configuration,\n ConfigurationParameters,\n FrontendApi,\n OAuth2Api,\n} from \"@ory/client-fetch\"\nimport { guessPotentiallyProxiedOrySdkUrl } from \"./config\"\n\nexport function frontendClient(\n {\n forceBaseUrl,\n ...opts\n }: Partial<ConfigurationParameters & { forceBaseUrl?: string }> = {\n credentials: \"include\",\n },\n) {\n const basePath =\n forceBaseUrl ??\n guessPotentiallyProxiedOrySdkUrl({\n knownProxiedUrl: window.location.origin,\n })\n\n const config = new Configuration({\n ...opts,\n basePath: basePath?.replace(/\\/$/, \"\"),\n credentials: opts.credentials ?? \"include\",\n headers: {\n Accept: \"application/json\",\n ...opts.headers,\n },\n })\n return new FrontendApi(config)\n}\n\nexport function oauth2Client(\n {\n forceBaseUrl,\n ...opts\n }: Partial<ConfigurationParameters & { forceBaseUrl?: string }> = {\n credentials: \"include\",\n },\n) {\n const basePath =\n forceBaseUrl ??\n guessPotentiallyProxiedOrySdkUrl({\n knownProxiedUrl: window.location.origin,\n })\n\n const config = new Configuration({\n ...opts,\n basePath: basePath?.replace(/\\/$/, \"\"),\n credentials: opts.credentials ?? \"include\",\n headers: {\n Accept: \"application/json\",\n ...opts.headers,\n },\n })\n return new OAuth2Api(config)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAKO;AACP,oBAAiD;AAE1C,SAAS,eACd;AAAA,EACE;AAAA,EACA,GAAG;AACL,IAAkE;AAAA,EAChE,aAAa;AACf,GACA;AAlBF;AAmBE,QAAM,WACJ,0CACA,gDAAiC;AAAA,IAC/B,iBAAiB,OAAO,SAAS;AAAA,EACnC,CAAC;AAEH,QAAM,SAAS,IAAI,kCAAc;AAAA,IAC/B,GAAG;AAAA,IACH,UAAU,qCAAU,QAAQ,OAAO;AAAA,IACnC,cAAa,UAAK,gBAAL,YAAoB;AAAA,IACjC,SAAS;AAAA,MACP,QAAQ;AAAA,MACR,GAAG,KAAK;AAAA,IACV;AAAA,EACF,CAAC;AACD,SAAO,IAAI,gCAAY,MAAM;AAC/B;AAEO,SAAS,aACd;AAAA,EACE;AAAA,EACA,GAAG;AACL,IAAkE;AAAA,EAChE,aAAa;AACf,GACA;AA5CF;AA6CE,QAAM,WACJ,0CACA,gDAAiC;AAAA,IAC/B,iBAAiB,OAAO,SAAS;AAAA,EACnC,CAAC;AAEH,QAAM,SAAS,IAAI,kCAAc;AAAA,IAC/B,GAAG;AAAA,IACH,UAAU,qCAAU,QAAQ,OAAO;AAAA,IACnC,cAAa,UAAK,gBAAL,YAAoB;AAAA,IACjC,SAAS;AAAA,MACP,QAAQ;AAAA,MACR,GAAG,KAAK;AAAA,IACV;AAAA,EACF,CAAC;AACD,SAAO,IAAI,8BAAU,MAAM;AAC7B;","names":[]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
Configuration,
|
|
4
|
+
FrontendApi,
|
|
5
|
+
OAuth2Api
|
|
6
|
+
} from "@ory/client-fetch";
|
|
7
|
+
import { guessPotentiallyProxiedOrySdkUrl } from "./config";
|
|
8
|
+
function frontendClient({
|
|
9
|
+
forceBaseUrl,
|
|
10
|
+
...opts
|
|
11
|
+
} = {
|
|
12
|
+
credentials: "include"
|
|
13
|
+
}) {
|
|
14
|
+
var _a;
|
|
15
|
+
const basePath = forceBaseUrl != null ? forceBaseUrl : guessPotentiallyProxiedOrySdkUrl({
|
|
16
|
+
knownProxiedUrl: window.location.origin
|
|
17
|
+
});
|
|
18
|
+
const config = new Configuration({
|
|
19
|
+
...opts,
|
|
20
|
+
basePath: basePath == null ? void 0 : basePath.replace(/\/$/, ""),
|
|
21
|
+
credentials: (_a = opts.credentials) != null ? _a : "include",
|
|
22
|
+
headers: {
|
|
23
|
+
Accept: "application/json",
|
|
24
|
+
...opts.headers
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return new FrontendApi(config);
|
|
28
|
+
}
|
|
29
|
+
function oauth2Client({
|
|
30
|
+
forceBaseUrl,
|
|
31
|
+
...opts
|
|
32
|
+
} = {
|
|
33
|
+
credentials: "include"
|
|
34
|
+
}) {
|
|
35
|
+
var _a;
|
|
36
|
+
const basePath = forceBaseUrl != null ? forceBaseUrl : guessPotentiallyProxiedOrySdkUrl({
|
|
37
|
+
knownProxiedUrl: window.location.origin
|
|
38
|
+
});
|
|
39
|
+
const config = new Configuration({
|
|
40
|
+
...opts,
|
|
41
|
+
basePath: basePath == null ? void 0 : basePath.replace(/\/$/, ""),
|
|
42
|
+
credentials: (_a = opts.credentials) != null ? _a : "include",
|
|
43
|
+
headers: {
|
|
44
|
+
Accept: "application/json",
|
|
45
|
+
...opts.headers
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return new OAuth2Api(config);
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
frontendClient,
|
|
52
|
+
oauth2Client
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=frontendClient.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/frontendClient.ts"],"sourcesContent":["// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\"use client\"\nimport {\n Configuration,\n ConfigurationParameters,\n FrontendApi,\n OAuth2Api,\n} from \"@ory/client-fetch\"\nimport { guessPotentiallyProxiedOrySdkUrl } from \"./config\"\n\nexport function frontendClient(\n {\n forceBaseUrl,\n ...opts\n }: Partial<ConfigurationParameters & { forceBaseUrl?: string }> = {\n credentials: \"include\",\n },\n) {\n const basePath =\n forceBaseUrl ??\n guessPotentiallyProxiedOrySdkUrl({\n knownProxiedUrl: window.location.origin,\n })\n\n const config = new Configuration({\n ...opts,\n basePath: basePath?.replace(/\\/$/, \"\"),\n credentials: opts.credentials ?? \"include\",\n headers: {\n Accept: \"application/json\",\n ...opts.headers,\n },\n })\n return new FrontendApi(config)\n}\n\nexport function oauth2Client(\n {\n forceBaseUrl,\n ...opts\n }: Partial<ConfigurationParameters & { forceBaseUrl?: string }> = {\n credentials: \"include\",\n },\n) {\n const basePath =\n forceBaseUrl ??\n guessPotentiallyProxiedOrySdkUrl({\n knownProxiedUrl: window.location.origin,\n })\n\n const config = new Configuration({\n ...opts,\n basePath: basePath?.replace(/\\/$/, \"\"),\n credentials: opts.credentials ?? \"include\",\n headers: {\n Accept: \"application/json\",\n ...opts.headers,\n },\n })\n return new OAuth2Api(config)\n}\n"],"mappings":";AAGA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wCAAwC;AAE1C,SAAS,eACd;AAAA,EACE;AAAA,EACA,GAAG;AACL,IAAkE;AAAA,EAChE,aAAa;AACf,GACA;AAlBF;AAmBE,QAAM,WACJ,sCACA,iCAAiC;AAAA,IAC/B,iBAAiB,OAAO,SAAS;AAAA,EACnC,CAAC;AAEH,QAAM,SAAS,IAAI,cAAc;AAAA,IAC/B,GAAG;AAAA,IACH,UAAU,qCAAU,QAAQ,OAAO;AAAA,IACnC,cAAa,UAAK,gBAAL,YAAoB;AAAA,IACjC,SAAS;AAAA,MACP,QAAQ;AAAA,MACR,GAAG,KAAK;AAAA,IACV;AAAA,EACF,CAAC;AACD,SAAO,IAAI,YAAY,MAAM;AAC/B;AAEO,SAAS,aACd;AAAA,EACE;AAAA,EACA,GAAG;AACL,IAAkE;AAAA,EAChE,aAAa;AACf,GACA;AA5CF;AA6CE,QAAM,WACJ,sCACA,iCAAiC;AAAA,IAC/B,iBAAiB,OAAO,SAAS;AAAA,EACnC,CAAC;AAEH,QAAM,SAAS,IAAI,cAAc;AAAA,IAC/B,GAAG;AAAA,IACH,UAAU,qCAAU,QAAQ,OAAO;AAAA,IACnC,cAAa,UAAK,gBAAL,YAAoB;AAAA,IACjC,SAAS;AAAA,MACP,QAAQ;AAAA,MACR,GAAG,KAAK;AAAA,IACV;AAAA,EACF,CAAC;AACD,SAAO,IAAI,UAAU,MAAM;AAC7B;","names":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
SessionProvider: () => import_session_provider.SessionProvider,
|
|
23
|
+
useSession: () => import_useSession.useSession
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_session_provider = require("./session-provider");
|
|
27
|
+
var import_useSession = require("./useSession");
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
SessionProvider,
|
|
31
|
+
useSession
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/index.ts"],"sourcesContent":["\"use client\"\n// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\nexport {\n SessionProvider,\n type SessionContextData,\n type SessionProviderProps,\n} from \"./session-provider\"\nexport { useSession } from \"./useSession\"\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,8BAIO;AACP,wBAA2B;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/index.ts"],"sourcesContent":["\"use client\"\n// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\nexport {\n SessionProvider,\n type SessionContextData,\n type SessionProviderProps,\n} from \"./session-provider\"\nexport { useSession } from \"./useSession\"\n"],"mappings":";AAIA;AAAA,EACE;AAAA,OAGK;AACP,SAAS,kBAAkB;","names":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { Session } from '@ory/client-fetch';
|
|
4
|
+
|
|
5
|
+
type SessionContextData = {
|
|
6
|
+
/**
|
|
7
|
+
* Whether the session is currently being loaded
|
|
8
|
+
*/
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether the session is being loaded for the first time
|
|
12
|
+
* Never true, if a session was passed to the provider
|
|
13
|
+
*/
|
|
14
|
+
initialized: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The current session or null if the user is not authenticated or an error occurred,
|
|
17
|
+
* when fetching the session
|
|
18
|
+
*/
|
|
19
|
+
session: Session | null;
|
|
20
|
+
/**
|
|
21
|
+
* The error that occurred when fetching the session if any
|
|
22
|
+
*/
|
|
23
|
+
error: Error | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Refetches the session
|
|
26
|
+
*/
|
|
27
|
+
refetch: () => Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
declare const SessionContext: react.Context<SessionContextData>;
|
|
30
|
+
type SessionProviderProps = {
|
|
31
|
+
session?: Session | null;
|
|
32
|
+
baseUrl?: string;
|
|
33
|
+
} & React.PropsWithChildren;
|
|
34
|
+
/**
|
|
35
|
+
* A provider that fetches the session from the Ory Network and provides it to the children.
|
|
36
|
+
*
|
|
37
|
+
* To use this provider, wrap your application in it:
|
|
38
|
+
*
|
|
39
|
+
* ```tsx
|
|
40
|
+
* import { SessionProvider } from "@ory/elements-react"
|
|
41
|
+
*
|
|
42
|
+
* export default function App() {
|
|
43
|
+
* return (
|
|
44
|
+
* <SessionProvider>
|
|
45
|
+
* <MyApp />
|
|
46
|
+
* </SessionProvider>
|
|
47
|
+
* )
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* If you have a session from the server, you can pass it to the provider:
|
|
52
|
+
*
|
|
53
|
+
* ```tsx
|
|
54
|
+
* <SessionProvider session={serverSession}>
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @see {@link useSession}
|
|
58
|
+
* @param props - The provider props
|
|
59
|
+
*/
|
|
60
|
+
declare function SessionProvider({ session: initialSession, children, baseUrl, }: SessionProviderProps): react_jsx_runtime.JSX.Element;
|
|
61
|
+
|
|
62
|
+
export { SessionContext, type SessionContextData, SessionProvider, type SessionProviderProps };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { Session } from '@ory/client-fetch';
|
|
4
|
+
|
|
5
|
+
type SessionContextData = {
|
|
6
|
+
/**
|
|
7
|
+
* Whether the session is currently being loaded
|
|
8
|
+
*/
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether the session is being loaded for the first time
|
|
12
|
+
* Never true, if a session was passed to the provider
|
|
13
|
+
*/
|
|
14
|
+
initialized: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The current session or null if the user is not authenticated or an error occurred,
|
|
17
|
+
* when fetching the session
|
|
18
|
+
*/
|
|
19
|
+
session: Session | null;
|
|
20
|
+
/**
|
|
21
|
+
* The error that occurred when fetching the session if any
|
|
22
|
+
*/
|
|
23
|
+
error: Error | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Refetches the session
|
|
26
|
+
*/
|
|
27
|
+
refetch: () => Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
declare const SessionContext: react.Context<SessionContextData>;
|
|
30
|
+
type SessionProviderProps = {
|
|
31
|
+
session?: Session | null;
|
|
32
|
+
baseUrl?: string;
|
|
33
|
+
} & React.PropsWithChildren;
|
|
34
|
+
/**
|
|
35
|
+
* A provider that fetches the session from the Ory Network and provides it to the children.
|
|
36
|
+
*
|
|
37
|
+
* To use this provider, wrap your application in it:
|
|
38
|
+
*
|
|
39
|
+
* ```tsx
|
|
40
|
+
* import { SessionProvider } from "@ory/elements-react"
|
|
41
|
+
*
|
|
42
|
+
* export default function App() {
|
|
43
|
+
* return (
|
|
44
|
+
* <SessionProvider>
|
|
45
|
+
* <MyApp />
|
|
46
|
+
* </SessionProvider>
|
|
47
|
+
* )
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* If you have a session from the server, you can pass it to the provider:
|
|
52
|
+
*
|
|
53
|
+
* ```tsx
|
|
54
|
+
* <SessionProvider session={serverSession}>
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @see {@link useSession}
|
|
58
|
+
* @param props - The provider props
|
|
59
|
+
*/
|
|
60
|
+
declare function SessionProvider({ session: initialSession, children, baseUrl, }: SessionProviderProps): react_jsx_runtime.JSX.Element;
|
|
61
|
+
|
|
62
|
+
export { SessionContext, type SessionContextData, SessionProvider, type SessionProviderProps };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var session_provider_exports = {};
|
|
21
|
+
__export(session_provider_exports, {
|
|
22
|
+
SessionContext: () => SessionContext,
|
|
23
|
+
SessionProvider: () => SessionProvider
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(session_provider_exports);
|
|
26
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
var import_frontendClient = require("./frontendClient");
|
|
29
|
+
const SessionContext = (0, import_react.createContext)({
|
|
30
|
+
session: null,
|
|
31
|
+
isLoading: false,
|
|
32
|
+
initialized: false,
|
|
33
|
+
error: void 0,
|
|
34
|
+
refetch: async () => {
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
function SessionProvider({
|
|
38
|
+
session: initialSession,
|
|
39
|
+
children,
|
|
40
|
+
baseUrl
|
|
41
|
+
}) {
|
|
42
|
+
const initialized = (0, import_react.useRef)(!!initialSession);
|
|
43
|
+
const [isLoading, setLoading] = (0, import_react.useState)(false);
|
|
44
|
+
const [sessionState, setSessionState] = (0, import_react.useState)(
|
|
45
|
+
() => {
|
|
46
|
+
if (initialSession) {
|
|
47
|
+
return {
|
|
48
|
+
session: initialSession,
|
|
49
|
+
state: initialSession.active ? "authenticated" : "unauthenticated"
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return void 0;
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
const fetchSession = (0, import_react.useCallback)(async () => {
|
|
56
|
+
try {
|
|
57
|
+
setLoading(true);
|
|
58
|
+
const session = await (0, import_frontendClient.frontendClient)({
|
|
59
|
+
forceBaseUrl: baseUrl
|
|
60
|
+
}).toSession();
|
|
61
|
+
setSessionState({
|
|
62
|
+
session,
|
|
63
|
+
state: session.active ? "authenticated" : "unauthenticated"
|
|
64
|
+
});
|
|
65
|
+
} catch (error) {
|
|
66
|
+
setSessionState({ state: "error", error });
|
|
67
|
+
} finally {
|
|
68
|
+
setLoading(false);
|
|
69
|
+
}
|
|
70
|
+
}, [baseUrl]);
|
|
71
|
+
(0, import_react.useEffect)(() => {
|
|
72
|
+
if (!initialized.current) {
|
|
73
|
+
initialized.current = true;
|
|
74
|
+
void fetchSession();
|
|
75
|
+
}
|
|
76
|
+
}, [fetchSession]);
|
|
77
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
78
|
+
SessionContext.Provider,
|
|
79
|
+
{
|
|
80
|
+
value: {
|
|
81
|
+
error: (sessionState == null ? void 0 : sessionState.state) === "error" ? sessionState.error : void 0,
|
|
82
|
+
session: (sessionState == null ? void 0 : sessionState.state) === "authenticated" ? sessionState.session : null,
|
|
83
|
+
isLoading,
|
|
84
|
+
initialized: initialized.current,
|
|
85
|
+
refetch: fetchSession
|
|
86
|
+
},
|
|
87
|
+
children
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
SessionContext,
|
|
94
|
+
SessionProvider
|
|
95
|
+
});
|
|
96
|
+
//# sourceMappingURL=session-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/session-provider.tsx"],"sourcesContent":["// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\n\"use client\"\nimport { Session } from \"@ory/client-fetch\"\nimport { createContext, useCallback, useEffect, useRef, useState } from \"react\"\nimport { frontendClient } from \"./frontendClient\"\n\ntype SessionState =\n | {\n session: Session\n state: \"authenticated\"\n }\n | {\n state: \"unauthenticated\"\n }\n | {\n state: \"error\"\n error: Error\n }\n\nexport type SessionContextData = {\n /**\n * Whether the session is currently being loaded\n */\n isLoading: boolean\n /**\n * Whether the session is being loaded for the first time\n * Never true, if a session was passed to the provider\n */\n initialized: boolean\n /**\n * The current session or null if the user is not authenticated or an error occurred,\n * when fetching the session\n */\n session: Session | null\n /**\n * The error that occurred when fetching the session if any\n */\n error: Error | undefined\n /**\n * Refetches the session\n */\n refetch: () => Promise<void>\n}\n\nexport const SessionContext = createContext<SessionContextData>({\n session: null,\n isLoading: false,\n initialized: false,\n error: undefined,\n refetch: async () => {},\n})\n\nexport type SessionProviderProps = {\n session?: Session | null\n baseUrl?: string\n} & React.PropsWithChildren\n\n/**\n * A provider that fetches the session from the Ory Network and provides it to the children.\n *\n * To use this provider, wrap your application in it:\n *\n * ```tsx\n * import { SessionProvider } from \"@ory/elements-react\"\n *\n * export default function App() {\n * return (\n * <SessionProvider>\n * <MyApp />\n * </SessionProvider>\n * )\n * }\n * ```\n *\n * If you have a session from the server, you can pass it to the provider:\n *\n * ```tsx\n * <SessionProvider session={serverSession}>\n * ```\n *\n * @see {@link useSession}\n * @param props - The provider props\n */\nexport function SessionProvider({\n session: initialSession,\n children,\n baseUrl,\n}: SessionProviderProps) {\n const initialized = useRef(!!initialSession)\n const [isLoading, setLoading] = useState(false)\n const [sessionState, setSessionState] = useState<SessionState | undefined>(\n () => {\n if (initialSession) {\n return {\n session: initialSession,\n state: initialSession.active ? \"authenticated\" : \"unauthenticated\",\n }\n }\n\n return undefined\n },\n )\n\n const fetchSession = useCallback(async () => {\n try {\n setLoading(true)\n const session = await frontendClient({\n forceBaseUrl: baseUrl,\n }).toSession()\n\n setSessionState({\n session,\n state: session.active ? \"authenticated\" : \"unauthenticated\",\n })\n } catch (error) {\n setSessionState({ state: \"error\", error: error as Error })\n } finally {\n setLoading(false)\n }\n }, [baseUrl])\n\n useEffect(() => {\n if (!initialized.current) {\n initialized.current = true\n void fetchSession()\n }\n }, [fetchSession])\n\n return (\n <SessionContext.Provider\n value={{\n error: sessionState?.state === \"error\" ? sessionState.error : undefined,\n session:\n sessionState?.state === \"authenticated\" ? sessionState.session : null,\n isLoading,\n initialized: initialized.current,\n refetch: fetchSession,\n }}\n >\n {children}\n </SessionContext.Provider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmII;AA9HJ,mBAAwE;AACxE,4BAA+B;AAwCxB,MAAM,qBAAiB,4BAAkC;AAAA,EAC9D,SAAS;AAAA,EACT,WAAW;AAAA,EACX,aAAa;AAAA,EACb,OAAO;AAAA,EACP,SAAS,YAAY;AAAA,EAAC;AACxB,CAAC;AAiCM,SAAS,gBAAgB;AAAA,EAC9B,SAAS;AAAA,EACT;AAAA,EACA;AACF,GAAyB;AACvB,QAAM,kBAAc,qBAAO,CAAC,CAAC,cAAc;AAC3C,QAAM,CAAC,WAAW,UAAU,QAAI,uBAAS,KAAK;AAC9C,QAAM,CAAC,cAAc,eAAe,QAAI;AAAA,IACtC,MAAM;AACJ,UAAI,gBAAgB;AAClB,eAAO;AAAA,UACL,SAAS;AAAA,UACT,OAAO,eAAe,SAAS,kBAAkB;AAAA,QACnD;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAEA,QAAM,mBAAe,0BAAY,YAAY;AAC3C,QAAI;AACF,iBAAW,IAAI;AACf,YAAM,UAAU,UAAM,sCAAe;AAAA,QACnC,cAAc;AAAA,MAChB,CAAC,EAAE,UAAU;AAEb,sBAAgB;AAAA,QACd;AAAA,QACA,OAAO,QAAQ,SAAS,kBAAkB;AAAA,MAC5C,CAAC;AAAA,IACH,SAAS,OAAO;AACd,sBAAgB,EAAE,OAAO,SAAS,MAAsB,CAAC;AAAA,IAC3D,UAAE;AACA,iBAAW,KAAK;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,8BAAU,MAAM;AACd,QAAI,CAAC,YAAY,SAAS;AACxB,kBAAY,UAAU;AACtB,WAAK,aAAa;AAAA,IACpB;AAAA,EACF,GAAG,CAAC,YAAY,CAAC;AAEjB,SACE;AAAA,IAAC,eAAe;AAAA,IAAf;AAAA,MACC,OAAO;AAAA,QACL,QAAO,6CAAc,WAAU,UAAU,aAAa,QAAQ;AAAA,QAC9D,UACE,6CAAc,WAAU,kBAAkB,aAAa,UAAU;AAAA,QACnE;AAAA,QACA,aAAa,YAAY;AAAA,QACzB,SAAS;AAAA,MACX;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;","names":[]}
|