next-auth-heksso 1.1.2 → 1.1.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/package.json
CHANGED
|
@@ -78,11 +78,24 @@ exports.KeycloakSessionProvider = KeycloakSessionProvider;
|
|
|
78
78
|
class _KeycloakSessionProvider extends react_2.Component {
|
|
79
79
|
constructor(props) {
|
|
80
80
|
super(props);
|
|
81
|
+
this.contextValue = {
|
|
82
|
+
getAccessToken: this.getAccessToken,
|
|
83
|
+
accessTokenError: this.state.accessTokenError
|
|
84
|
+
};
|
|
81
85
|
this.state = {
|
|
82
86
|
accessTokenError: false
|
|
83
87
|
};
|
|
84
88
|
this.getAccessToken = this.getAccessToken.bind(this);
|
|
85
89
|
}
|
|
90
|
+
getContextValue() {
|
|
91
|
+
if (this.state.accessTokenError !== this.contextValue.accessTokenError) {
|
|
92
|
+
this.contextValue = {
|
|
93
|
+
getAccessToken: this.getAccessToken,
|
|
94
|
+
accessTokenError: this.state.accessTokenError
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return this.contextValue;
|
|
98
|
+
}
|
|
86
99
|
getAccessToken() {
|
|
87
100
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
101
|
if (!this.state.accessToken)
|
|
@@ -140,10 +153,7 @@ class _KeycloakSessionProvider extends react_2.Component {
|
|
|
140
153
|
}
|
|
141
154
|
}
|
|
142
155
|
render() {
|
|
143
|
-
return (react_2.default.createElement(exports.KeycloakSessionContext.Provider, { value:
|
|
144
|
-
getAccessToken: this.getAccessToken,
|
|
145
|
-
accessTokenError: this.state.accessTokenError
|
|
146
|
-
} }, this.props.children));
|
|
156
|
+
return (react_2.default.createElement(exports.KeycloakSessionContext.Provider, { value: this.getContextValue() }, this.props.children));
|
|
147
157
|
}
|
|
148
158
|
}
|
|
149
159
|
function sessionDataGuard(sessionData) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { signOut, useSession } from "next-auth/react"
|
|
2
2
|
import { NextRouter, useRouter } from "next/router"
|
|
3
|
-
import React, { Component, createContext, PropsWithChildren, useContext } from "react"
|
|
3
|
+
import React, { Component, createContext, memo, PropsWithChildren, useContext } from "react"
|
|
4
4
|
|
|
5
5
|
export interface KeycloakSession {
|
|
6
6
|
accessTokenError: boolean
|
|
@@ -82,6 +82,22 @@ class _KeycloakSessionProvider extends Component<
|
|
|
82
82
|
this.getAccessToken = this.getAccessToken.bind(this)
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
private contextValue = {
|
|
86
|
+
getAccessToken: this.getAccessToken,
|
|
87
|
+
accessTokenError: this.state.accessTokenError
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private getContextValue() {
|
|
91
|
+
if (this.state.accessTokenError !== this.contextValue.accessTokenError) {
|
|
92
|
+
this.contextValue = {
|
|
93
|
+
getAccessToken: this.getAccessToken,
|
|
94
|
+
accessTokenError: this.state.accessTokenError
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return this.contextValue
|
|
99
|
+
}
|
|
100
|
+
|
|
85
101
|
async getAccessToken() {
|
|
86
102
|
if (!this.state.accessToken) return undefined
|
|
87
103
|
if (this.state.accessTokenExpires && Date.now() >= this.state.accessTokenExpires) {
|
|
@@ -139,12 +155,7 @@ class _KeycloakSessionProvider extends Component<
|
|
|
139
155
|
|
|
140
156
|
render() {
|
|
141
157
|
return (
|
|
142
|
-
<KeycloakSessionContext.Provider
|
|
143
|
-
value={{
|
|
144
|
-
getAccessToken: this.getAccessToken,
|
|
145
|
-
accessTokenError: this.state.accessTokenError
|
|
146
|
-
}}
|
|
147
|
-
>
|
|
158
|
+
<KeycloakSessionContext.Provider value={this.getContextValue()}>
|
|
148
159
|
{this.props.children}
|
|
149
160
|
</KeycloakSessionContext.Provider>
|
|
150
161
|
)
|