acinguiux-dnr-utils 0.0.1 → 0.0.2
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/package.json
CHANGED
|
@@ -4,11 +4,17 @@ import type { Session } from "next-auth";
|
|
|
4
4
|
import { callbacks } from "./callbacks";
|
|
5
5
|
import PingID from "./provider";
|
|
6
6
|
|
|
7
|
+
type AuthSession = Session & {
|
|
8
|
+
expires_at?: number;
|
|
9
|
+
access_token?: string;
|
|
10
|
+
refresh_token?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
7
13
|
const isAuthDisabled = ["true", "1", "yes"].includes(
|
|
8
14
|
(process.env.AUTH_DISABLED || "").toLowerCase(),
|
|
9
15
|
);
|
|
10
16
|
|
|
11
|
-
const mockSession:
|
|
17
|
+
const mockSession: AuthSession = {
|
|
12
18
|
user: {
|
|
13
19
|
name: "Local User",
|
|
14
20
|
email: "local.user@example.com",
|
|
@@ -2,7 +2,19 @@ import type { NextRequest } from "next/server.js";
|
|
|
2
2
|
import type { Account, Session } from "next-auth";
|
|
3
3
|
import type { JWT } from "next-auth/jwt";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
type AuthJWT = JWT & {
|
|
6
|
+
expires_at?: number;
|
|
7
|
+
access_token?: string;
|
|
8
|
+
refresh_token?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type AuthSession = Session & {
|
|
12
|
+
expires_at?: number;
|
|
13
|
+
access_token?: string;
|
|
14
|
+
refresh_token?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
async function jwt({ token, account }: { token: AuthJWT; account?: Account | null }) {
|
|
6
18
|
// The first time jwt is called, account exists. We map fields from account to token
|
|
7
19
|
// which is passed to the session callback. User is also available in this callback which
|
|
8
20
|
// comes from the profile function in the provider. We can use this in the future to surface
|
|
@@ -46,7 +58,7 @@ async function jwt({ token, account }: { token: JWT; account?: Account | null })
|
|
|
46
58
|
return token;
|
|
47
59
|
}
|
|
48
60
|
|
|
49
|
-
async function session({ session, token }: { session:
|
|
61
|
+
async function session({ session, token }: { session: AuthSession; token: AuthJWT }) {
|
|
50
62
|
// We map fields from token to make them available in the session.
|
|
51
63
|
session.expires_at = token.expires_at;
|
|
52
64
|
session.access_token = token.access_token;
|
|
@@ -54,7 +66,7 @@ async function session({ session, token }: { session: Session; token: JWT }) {
|
|
|
54
66
|
return session;
|
|
55
67
|
}
|
|
56
68
|
|
|
57
|
-
async function authorized({ auth }: { request: NextRequest; auth:
|
|
69
|
+
async function authorized({ auth }: { request: NextRequest; auth: AuthSession | null }) {
|
|
58
70
|
// If there is no access token, the user is not authorized. Returning false from this
|
|
59
71
|
// callback will redirect the user to the sign in page.
|
|
60
72
|
|