next-auth-heksso 1.0.5 → 1.0.6
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.
|
@@ -37,6 +37,8 @@ const react_1 = require("next-auth/react");
|
|
|
37
37
|
const router_1 = require("next/router");
|
|
38
38
|
const react_2 = __importStar(require("react"));
|
|
39
39
|
exports.KeycloakSessionContext = (0, react_2.createContext)({
|
|
40
|
+
isAuthenticated: false,
|
|
41
|
+
accessTokenError: false,
|
|
40
42
|
getAccessToken: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
43
|
return "";
|
|
42
44
|
})
|
|
@@ -97,6 +99,9 @@ function KeycloakSessionProvider(props) {
|
|
|
97
99
|
else
|
|
98
100
|
return accessToken;
|
|
99
101
|
}), [accessToken, accessTokenExpires]);
|
|
102
|
+
const isAuthenticated = (0, react_2.useMemo)(() => {
|
|
103
|
+
return typeof accessToken === "string" && accessToken.length > 0;
|
|
104
|
+
}, [accessToken]);
|
|
100
105
|
// Because this component is present on every page that requires a session,
|
|
101
106
|
// we check for a valid refresh token here
|
|
102
107
|
(0, react_2.useEffect)(() => {
|
|
@@ -118,6 +123,6 @@ function KeycloakSessionProvider(props) {
|
|
|
118
123
|
setAccessTokenExpires(undefined);
|
|
119
124
|
}
|
|
120
125
|
}, [session, router.pathname, accessToken, router, props.signInPage, accessTokenError]);
|
|
121
|
-
return (react_2.default.createElement(exports.KeycloakSessionContext.Provider, { value: { getAccessToken } }, props.children));
|
|
126
|
+
return (react_2.default.createElement(exports.KeycloakSessionContext.Provider, { value: { getAccessToken, isAuthenticated, accessTokenError } }, props.children));
|
|
122
127
|
}
|
|
123
128
|
exports.KeycloakSessionProvider = KeycloakSessionProvider;
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { signOut, useSession } from "next-auth/react"
|
|
2
2
|
import { useRouter } from "next/router"
|
|
3
|
-
import React, { createContext, ReactNode, useCallback, useEffect, useState } from "react"
|
|
3
|
+
import React, { createContext, ReactNode, useCallback, useEffect, useMemo, useState } from "react"
|
|
4
4
|
|
|
5
5
|
export interface KeycloakSession {
|
|
6
|
+
isAuthenticated: boolean
|
|
7
|
+
accessTokenError: boolean
|
|
6
8
|
getAccessToken: () => Promise<string>
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
export const KeycloakSessionContext = createContext<KeycloakSession>({
|
|
12
|
+
isAuthenticated: false,
|
|
13
|
+
accessTokenError: false,
|
|
10
14
|
getAccessToken: async () => {
|
|
11
15
|
return ""
|
|
12
16
|
}
|
|
@@ -71,6 +75,10 @@ export function KeycloakSessionProvider(props: {
|
|
|
71
75
|
} else return accessToken
|
|
72
76
|
}, [accessToken, accessTokenExpires])
|
|
73
77
|
|
|
78
|
+
const isAuthenticated = useMemo(() => {
|
|
79
|
+
return typeof accessToken === "string" && accessToken.length > 0
|
|
80
|
+
}, [accessToken])
|
|
81
|
+
|
|
74
82
|
// Because this component is present on every page that requires a session,
|
|
75
83
|
// we check for a valid refresh token here
|
|
76
84
|
useEffect(() => {
|
|
@@ -95,7 +103,7 @@ export function KeycloakSessionProvider(props: {
|
|
|
95
103
|
|
|
96
104
|
return (
|
|
97
105
|
<KeycloakSessionContext.Provider
|
|
98
|
-
value={{ getAccessToken }}
|
|
106
|
+
value={{ getAccessToken, isAuthenticated, accessTokenError }}
|
|
99
107
|
>
|
|
100
108
|
{props.children}
|
|
101
109
|
</KeycloakSessionContext.Provider>
|