@auditauth/next 0.2.0-beta.2 → 0.2.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/facade/createAuditAuth.cjs +78 -0
- package/dist/facade/createAuditAuth.d.cts +29 -0
- package/dist/facade/createAuditAuth.d.ts +6 -6
- package/dist/facade/createAuditAuth.js +52 -50
- package/dist/facade/index.cjs +22 -0
- package/dist/facade/index.d.cts +4 -0
- package/dist/facade/index.d.ts +4 -1
- package/dist/facade/index.js +1 -1
- package/dist/guard.cjs +74 -0
- package/dist/guard.d.cts +13 -0
- package/dist/guard.d.ts +5 -2
- package/dist/guard.js +43 -43
- package/dist/helpers.cjs +41 -0
- package/dist/helpers.d.cts +5 -0
- package/dist/helpers.d.ts +2 -1
- package/dist/helpers.js +9 -8
- package/dist/index.cjs +46 -0
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.js +14 -5
- package/dist/request.cjs +86 -0
- package/dist/request.d.cts +3 -0
- package/dist/request.d.ts +1 -0
- package/dist/request.js +55 -54
- package/dist/sdk.cjs +335 -0
- package/dist/sdk.d.cts +38 -0
- package/dist/sdk.d.ts +4 -2
- package/dist/sdk.js +299 -288
- package/dist/settings.cjs +43 -0
- package/dist/settings.d.cts +32 -0
- package/dist/settings.d.ts +1 -0
- package/dist/settings.js +17 -15
- package/dist/types.cjs +16 -0
- package/dist/types.d.cts +19 -0
- package/dist/types.d.ts +4 -2
- package/dist/types.js +0 -1
- package/package.json +14 -9
package/README.md
CHANGED
|
@@ -12,6 +12,17 @@ Install the package in your Next.js application.
|
|
|
12
12
|
npm install @auditauth/next
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
## TypeScript import compatibility
|
|
16
|
+
|
|
17
|
+
`@auditauth/next` ships dual module output (ESM + CJS) with declaration files.
|
|
18
|
+
You can import it in TypeScript projects with standard syntax:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { createAuditAuthNext } from '@auditauth/next'
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
You do not need to append `.js` in consumer imports.
|
|
25
|
+
|
|
15
26
|
## Create the AuditAuth provider
|
|
16
27
|
|
|
17
28
|
Create one shared instance with `createAuditAuthNext()`.
|
|
@@ -0,0 +1,78 @@
|
|
|
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 createAuditAuth_exports = {};
|
|
20
|
+
__export(createAuditAuth_exports, {
|
|
21
|
+
createAuditAuthNext: () => createAuditAuthNext
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(createAuditAuth_exports);
|
|
24
|
+
var import_headers = require("next/headers.js");
|
|
25
|
+
var import_sdk = require("../sdk.js");
|
|
26
|
+
var import_settings = require("../settings.js");
|
|
27
|
+
function createAuditAuthNext(config) {
|
|
28
|
+
const base = new URL(config.baseUrl);
|
|
29
|
+
async function createInstance() {
|
|
30
|
+
const store = await (0, import_headers.cookies)();
|
|
31
|
+
return new import_sdk.AuditAuthNext(config, {
|
|
32
|
+
get: (name) => store.get(name)?.value,
|
|
33
|
+
set: (name, value, options) => store.set(name, value, options),
|
|
34
|
+
remove: (name) => store.delete(name)
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
handlers: {
|
|
39
|
+
GET: async (req, ctx) => {
|
|
40
|
+
const instance = await createInstance();
|
|
41
|
+
return instance.getHandlers().GET(req, ctx);
|
|
42
|
+
},
|
|
43
|
+
POST: async (req, ctx) => {
|
|
44
|
+
const instance = await createInstance();
|
|
45
|
+
return instance.getHandlers().POST(req, ctx);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
middleware: async (req) => {
|
|
49
|
+
const instance = await createInstance();
|
|
50
|
+
return instance.middleware(req);
|
|
51
|
+
},
|
|
52
|
+
getSession: async () => {
|
|
53
|
+
const instance = await createInstance();
|
|
54
|
+
return instance.getSession();
|
|
55
|
+
},
|
|
56
|
+
hasSession: async () => {
|
|
57
|
+
const instance = await createInstance();
|
|
58
|
+
return instance.hasSession();
|
|
59
|
+
},
|
|
60
|
+
fetch: async (url, init) => {
|
|
61
|
+
const instance = await createInstance();
|
|
62
|
+
return instance.fetch(url, init);
|
|
63
|
+
},
|
|
64
|
+
withAuthRequest: (handler) => {
|
|
65
|
+
return async (req, ctx) => {
|
|
66
|
+
const instance = await createInstance();
|
|
67
|
+
return instance.withAuthRequest(handler)(req, ctx);
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
getLoginUrl: () => new URL(import_settings.SETTINGS.bff.paths.login, base),
|
|
71
|
+
getLogoutUrl: () => new URL(import_settings.SETTINGS.bff.paths.logout, base),
|
|
72
|
+
getPortalUrl: () => new URL(import_settings.SETTINGS.bff.paths.portal, base)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
createAuditAuthNext
|
|
78
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server.js';
|
|
2
|
+
import { SessionUser, AuditAuthConfig } from '@auditauth/core';
|
|
3
|
+
import { AuditAuthTokenPayload } from '@auditauth/node';
|
|
4
|
+
|
|
5
|
+
type AuditAuthNextFacade = {
|
|
6
|
+
handlers: {
|
|
7
|
+
GET: (req: NextRequest, ctx: {
|
|
8
|
+
params: Promise<{
|
|
9
|
+
auditauth: string[];
|
|
10
|
+
}>;
|
|
11
|
+
}) => Promise<Response>;
|
|
12
|
+
POST: (req: NextRequest, ctx: {
|
|
13
|
+
params: Promise<{
|
|
14
|
+
auditauth: string[];
|
|
15
|
+
}>;
|
|
16
|
+
}) => Promise<Response>;
|
|
17
|
+
};
|
|
18
|
+
middleware: (req: NextRequest) => Promise<NextResponse>;
|
|
19
|
+
getSession: () => Promise<SessionUser | null>;
|
|
20
|
+
hasSession: () => Promise<boolean>;
|
|
21
|
+
fetch: (url: string, init?: RequestInit) => Promise<Response>;
|
|
22
|
+
getLoginUrl: () => URL;
|
|
23
|
+
getLogoutUrl: () => URL;
|
|
24
|
+
getPortalUrl: () => URL;
|
|
25
|
+
withAuthRequest: <C>(handler: (req: NextRequest, ctx: C, session: AuditAuthTokenPayload) => Promise<Response>) => (req: NextRequest, ctx: C) => Promise<Response>;
|
|
26
|
+
};
|
|
27
|
+
declare function createAuditAuthNext(config: AuditAuthConfig): AuditAuthNextFacade;
|
|
28
|
+
|
|
29
|
+
export { type AuditAuthNextFacade, createAuditAuthNext };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server.js';
|
|
2
|
+
import { SessionUser, AuditAuthConfig } from '@auditauth/core';
|
|
3
|
+
import { AuditAuthTokenPayload } from '@auditauth/node';
|
|
4
|
+
|
|
5
5
|
type AuditAuthNextFacade = {
|
|
6
6
|
handlers: {
|
|
7
7
|
GET: (req: NextRequest, ctx: {
|
|
@@ -25,5 +25,5 @@ type AuditAuthNextFacade = {
|
|
|
25
25
|
withAuthRequest: <C>(handler: (req: NextRequest, ctx: C, session: AuditAuthTokenPayload) => Promise<Response>) => (req: NextRequest, ctx: C) => Promise<Response>;
|
|
26
26
|
};
|
|
27
27
|
declare function createAuditAuthNext(config: AuditAuthConfig): AuditAuthNextFacade;
|
|
28
|
-
|
|
29
|
-
export { createAuditAuthNext };
|
|
28
|
+
|
|
29
|
+
export { type AuditAuthNextFacade, createAuditAuthNext };
|
|
@@ -1,52 +1,54 @@
|
|
|
1
|
-
import { cookies } from
|
|
2
|
-
import { AuditAuthNext } from
|
|
3
|
-
import { SETTINGS } from
|
|
1
|
+
import { cookies } from "next/headers.js";
|
|
2
|
+
import { AuditAuthNext } from "../sdk.js";
|
|
3
|
+
import { SETTINGS } from "../settings.js";
|
|
4
4
|
function createAuditAuthNext(config) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
5
|
+
const base = new URL(config.baseUrl);
|
|
6
|
+
async function createInstance() {
|
|
7
|
+
const store = await cookies();
|
|
8
|
+
return new AuditAuthNext(config, {
|
|
9
|
+
get: (name) => store.get(name)?.value,
|
|
10
|
+
set: (name, value, options) => store.set(name, value, options),
|
|
11
|
+
remove: (name) => store.delete(name)
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
handlers: {
|
|
16
|
+
GET: async (req, ctx) => {
|
|
17
|
+
const instance = await createInstance();
|
|
18
|
+
return instance.getHandlers().GET(req, ctx);
|
|
19
|
+
},
|
|
20
|
+
POST: async (req, ctx) => {
|
|
21
|
+
const instance = await createInstance();
|
|
22
|
+
return instance.getHandlers().POST(req, ctx);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
middleware: async (req) => {
|
|
26
|
+
const instance = await createInstance();
|
|
27
|
+
return instance.middleware(req);
|
|
28
|
+
},
|
|
29
|
+
getSession: async () => {
|
|
30
|
+
const instance = await createInstance();
|
|
31
|
+
return instance.getSession();
|
|
32
|
+
},
|
|
33
|
+
hasSession: async () => {
|
|
34
|
+
const instance = await createInstance();
|
|
35
|
+
return instance.hasSession();
|
|
36
|
+
},
|
|
37
|
+
fetch: async (url, init) => {
|
|
38
|
+
const instance = await createInstance();
|
|
39
|
+
return instance.fetch(url, init);
|
|
40
|
+
},
|
|
41
|
+
withAuthRequest: (handler) => {
|
|
42
|
+
return async (req, ctx) => {
|
|
43
|
+
const instance = await createInstance();
|
|
44
|
+
return instance.withAuthRequest(handler)(req, ctx);
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
getLoginUrl: () => new URL(SETTINGS.bff.paths.login, base),
|
|
48
|
+
getLogoutUrl: () => new URL(SETTINGS.bff.paths.logout, base),
|
|
49
|
+
getPortalUrl: () => new URL(SETTINGS.bff.paths.portal, base)
|
|
50
|
+
};
|
|
51
51
|
}
|
|
52
|
-
export {
|
|
52
|
+
export {
|
|
53
|
+
createAuditAuthNext
|
|
54
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var facade_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(facade_exports);
|
|
18
|
+
__reExport(facade_exports, require("./createAuditAuth.js"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./createAuditAuth.js")
|
|
22
|
+
});
|
package/dist/facade/index.d.ts
CHANGED
package/dist/facade/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./createAuditAuth.js";
|
package/dist/guard.cjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
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 guard_exports = {};
|
|
21
|
+
__export(guard_exports, {
|
|
22
|
+
AuditAuthGuard: () => AuditAuthGuard,
|
|
23
|
+
useAuditAuth: () => useAuditAuth
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(guard_exports);
|
|
26
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
var import_settings = require("./settings.js");
|
|
29
|
+
const AuthContext = (0, import_react.createContext)(null);
|
|
30
|
+
const useAuditAuth = () => {
|
|
31
|
+
const ctx = (0, import_react.useContext)(AuthContext);
|
|
32
|
+
if (!ctx) {
|
|
33
|
+
throw new Error("useAuditAuth must be used within AuditAuthProvider");
|
|
34
|
+
}
|
|
35
|
+
return ctx;
|
|
36
|
+
};
|
|
37
|
+
const AuditAuthGuard = (props) => {
|
|
38
|
+
const [user, setUser] = (0, import_react.useState)({});
|
|
39
|
+
(0, import_react.useEffect)(() => {
|
|
40
|
+
let cancelled = false;
|
|
41
|
+
const checkSession = async () => {
|
|
42
|
+
try {
|
|
43
|
+
const response = await fetch(import_settings.SETTINGS.bff.paths.session, {
|
|
44
|
+
credentials: "include",
|
|
45
|
+
cache: "no-store"
|
|
46
|
+
});
|
|
47
|
+
if (cancelled) return;
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
window.location.href = import_settings.SETTINGS.bff.paths.login;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const data = await response.json();
|
|
53
|
+
setUser(data.user);
|
|
54
|
+
} catch {
|
|
55
|
+
window.location.href = import_settings.SETTINGS.bff.paths.login;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
checkSession();
|
|
60
|
+
return () => {
|
|
61
|
+
cancelled = true;
|
|
62
|
+
};
|
|
63
|
+
}, []);
|
|
64
|
+
const value = (0, import_react.useMemo)(() => ({
|
|
65
|
+
user
|
|
66
|
+
}), [user]);
|
|
67
|
+
if (!user.name) return null;
|
|
68
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AuthContext.Provider, { value, children: props.children });
|
|
69
|
+
};
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
AuditAuthGuard,
|
|
73
|
+
useAuditAuth
|
|
74
|
+
});
|
package/dist/guard.d.cts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { SessionUser } from '@auditauth/core';
|
|
3
|
+
|
|
4
|
+
type AuthContextValue = {
|
|
5
|
+
user: SessionUser;
|
|
6
|
+
};
|
|
7
|
+
declare const useAuditAuth: () => AuthContextValue;
|
|
8
|
+
type AuditAuthGuardProps = {
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
};
|
|
11
|
+
declare const AuditAuthGuard: (props: AuditAuthGuardProps) => react_jsx_runtime.JSX.Element | null;
|
|
12
|
+
|
|
13
|
+
export { AuditAuthGuard, useAuditAuth };
|
package/dist/guard.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { SessionUser } from '@auditauth/core';
|
|
3
|
+
|
|
2
4
|
type AuthContextValue = {
|
|
3
5
|
user: SessionUser;
|
|
4
6
|
};
|
|
@@ -6,5 +8,6 @@ declare const useAuditAuth: () => AuthContextValue;
|
|
|
6
8
|
type AuditAuthGuardProps = {
|
|
7
9
|
children: React.ReactNode;
|
|
8
10
|
};
|
|
9
|
-
declare const AuditAuthGuard: (props: AuditAuthGuardProps) =>
|
|
11
|
+
declare const AuditAuthGuard: (props: AuditAuthGuardProps) => react_jsx_runtime.JSX.Element | null;
|
|
12
|
+
|
|
10
13
|
export { AuditAuthGuard, useAuditAuth };
|
package/dist/guard.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
import { jsx
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, useContext, useEffect, useMemo, useState } from "react";
|
|
4
|
-
import { SETTINGS } from
|
|
4
|
+
import { SETTINGS } from "./settings.js";
|
|
5
5
|
const AuthContext = createContext(null);
|
|
6
6
|
const useAuditAuth = () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const ctx = useContext(AuthContext);
|
|
8
|
+
if (!ctx) {
|
|
9
|
+
throw new Error("useAuditAuth must be used within AuditAuthProvider");
|
|
10
|
+
}
|
|
11
|
+
return ctx;
|
|
12
12
|
};
|
|
13
13
|
const AuditAuthGuard = (props) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
14
|
+
const [user, setUser] = useState({});
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
let cancelled = false;
|
|
17
|
+
const checkSession = async () => {
|
|
18
|
+
try {
|
|
19
|
+
const response = await fetch(SETTINGS.bff.paths.session, {
|
|
20
|
+
credentials: "include",
|
|
21
|
+
cache: "no-store"
|
|
22
|
+
});
|
|
23
|
+
if (cancelled) return;
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
window.location.href = SETTINGS.bff.paths.login;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const data = await response.json();
|
|
29
|
+
setUser(data.user);
|
|
30
|
+
} catch {
|
|
31
|
+
window.location.href = SETTINGS.bff.paths.login;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
checkSession();
|
|
36
|
+
return () => {
|
|
37
|
+
cancelled = true;
|
|
38
|
+
};
|
|
39
|
+
}, []);
|
|
40
|
+
const value = useMemo(() => ({
|
|
41
|
+
user
|
|
42
|
+
}), [user]);
|
|
43
|
+
if (!user.name) return null;
|
|
44
|
+
return /* @__PURE__ */ jsx(AuthContext.Provider, { value, children: props.children });
|
|
45
|
+
};
|
|
46
|
+
export {
|
|
47
|
+
AuditAuthGuard,
|
|
48
|
+
useAuditAuth
|
|
48
49
|
};
|
|
49
|
-
export { AuditAuthGuard, useAuditAuth };
|
package/dist/helpers.cjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
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 helpers_exports = {};
|
|
20
|
+
__export(helpers_exports, {
|
|
21
|
+
goToPortal: () => goToPortal,
|
|
22
|
+
login: () => login,
|
|
23
|
+
logout: () => logout
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(helpers_exports);
|
|
26
|
+
var import_settings = require("./settings.js");
|
|
27
|
+
const login = () => {
|
|
28
|
+
window.location.href = import_settings.SETTINGS.bff.paths.login;
|
|
29
|
+
};
|
|
30
|
+
const logout = () => {
|
|
31
|
+
window.location.href = import_settings.SETTINGS.bff.paths.logout;
|
|
32
|
+
};
|
|
33
|
+
const goToPortal = () => {
|
|
34
|
+
window.location.href = import_settings.SETTINGS.bff.paths.portal;
|
|
35
|
+
};
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
goToPortal,
|
|
39
|
+
login,
|
|
40
|
+
logout
|
|
41
|
+
});
|
package/dist/helpers.d.ts
CHANGED
package/dist/helpers.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
/* CLIENT SHORTCUTS */
|
|
3
|
-
/* -------------------------------------------------------------------------- */
|
|
4
|
-
import { SETTINGS } from './settings.js';
|
|
1
|
+
import { SETTINGS } from "./settings.js";
|
|
5
2
|
const login = () => {
|
|
6
|
-
|
|
3
|
+
window.location.href = SETTINGS.bff.paths.login;
|
|
7
4
|
};
|
|
8
5
|
const logout = () => {
|
|
9
|
-
|
|
6
|
+
window.location.href = SETTINGS.bff.paths.logout;
|
|
10
7
|
};
|
|
11
8
|
const goToPortal = () => {
|
|
12
|
-
|
|
9
|
+
window.location.href = SETTINGS.bff.paths.portal;
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
goToPortal,
|
|
13
|
+
login,
|
|
14
|
+
logout
|
|
13
15
|
};
|
|
14
|
-
export { login, logout, goToPortal };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
AuditAuthGuard: () => import_guard.AuditAuthGuard,
|
|
23
|
+
AuditAuthNext: () => import_sdk.AuditAuthNext,
|
|
24
|
+
auditauthFetch: () => import_request.auditauthFetch,
|
|
25
|
+
goToPortal: () => import_helpers.goToPortal,
|
|
26
|
+
login: () => import_helpers.login,
|
|
27
|
+
logout: () => import_helpers.logout,
|
|
28
|
+
useAuditAuth: () => import_guard.useAuditAuth
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(index_exports);
|
|
31
|
+
var import_sdk = require("./sdk.js");
|
|
32
|
+
var import_guard = require("./guard.js");
|
|
33
|
+
var import_helpers = require("./helpers.js");
|
|
34
|
+
var import_request = require("./request.js");
|
|
35
|
+
__reExport(index_exports, require("./facade/index.js"), module.exports);
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
AuditAuthGuard,
|
|
39
|
+
AuditAuthNext,
|
|
40
|
+
auditauthFetch,
|
|
41
|
+
goToPortal,
|
|
42
|
+
login,
|
|
43
|
+
logout,
|
|
44
|
+
useAuditAuth,
|
|
45
|
+
...require("./facade/index.js")
|
|
46
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { AuditAuthNext } from './sdk.cjs';
|
|
2
|
+
export { AuditAuthGuard, useAuditAuth } from './guard.cjs';
|
|
3
|
+
export { goToPortal, login, logout } from './helpers.cjs';
|
|
4
|
+
export { auditauthFetch } from './request.cjs';
|
|
5
|
+
export { CookieAdapter, CookieOptions, Session } from './types.cjs';
|
|
6
|
+
export { AuditAuthNextFacade, createAuditAuthNext } from './facade/createAuditAuth.cjs';
|
|
7
|
+
import 'next/server.js';
|
|
8
|
+
import '@auditauth/core';
|
|
9
|
+
import '@auditauth/node';
|
|
10
|
+
import 'react/jsx-runtime';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export { AuditAuthNext } from './sdk.js';
|
|
2
2
|
export { AuditAuthGuard, useAuditAuth } from './guard.js';
|
|
3
|
-
export { login, logout
|
|
3
|
+
export { goToPortal, login, logout } from './helpers.js';
|
|
4
4
|
export { auditauthFetch } from './request.js';
|
|
5
|
-
export
|
|
6
|
-
export
|
|
5
|
+
export { CookieAdapter, CookieOptions, Session } from './types.js';
|
|
6
|
+
export { AuditAuthNextFacade, createAuditAuthNext } from './facade/createAuditAuth.js';
|
|
7
|
+
import 'next/server.js';
|
|
8
|
+
import '@auditauth/core';
|
|
9
|
+
import '@auditauth/node';
|
|
10
|
+
import 'react/jsx-runtime';
|