@ssplib/react-components 0.0.289 → 0.0.291
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.
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { User } from '../../types/auth';
|
|
3
|
-
interface AuthContextData {
|
|
4
|
-
user: User | null | undefined;
|
|
5
|
-
isAuth: boolean;
|
|
6
|
-
userLoaded: boolean;
|
|
7
|
-
login: () => void;
|
|
8
|
-
logout: () => void;
|
|
9
|
-
saveUserData: () => void;
|
|
10
|
-
refreshTokens: () => Promise<boolean>;
|
|
11
|
-
type: 'govbr' | 'ad';
|
|
12
|
-
}
|
|
13
|
-
export declare const AuthContext: React.Context<AuthContextData>;
|
|
1
|
+
/// <reference types="react" />
|
|
14
2
|
export declare const cookieName = "nextauth.token";
|
|
15
3
|
export declare function KeycloakAuthProvider({ url, realm, clientId, children, type, resource_name, redirectUri, }: {
|
|
16
4
|
url: string;
|
|
@@ -21,4 +9,3 @@ export declare function KeycloakAuthProvider({ url, realm, clientId, children, t
|
|
|
21
9
|
resource_name?: string;
|
|
22
10
|
redirectUri?: string;
|
|
23
11
|
}): JSX.Element;
|
|
24
|
-
export {};
|
|
@@ -35,11 +35,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.KeycloakAuthProvider = exports.cookieName =
|
|
38
|
+
exports.KeycloakAuthProvider = exports.cookieName = void 0;
|
|
39
39
|
const keycloak_js_1 = __importDefault(require("keycloak-js"));
|
|
40
40
|
const router_1 = require("next/router");
|
|
41
41
|
const react_1 = __importStar(require("react"));
|
|
42
|
-
|
|
42
|
+
const auth_1 = require("../../context/auth");
|
|
43
43
|
exports.cookieName = 'nextauth.token';
|
|
44
44
|
const userImgName = 'user-data.img';
|
|
45
45
|
function KeycloakAuthProvider({ url, realm, clientId, children, type = 'ad', resource_name = 'eventos-front', redirectUri = '', }) {
|
|
@@ -74,7 +74,11 @@ function KeycloakAuthProvider({ url, realm, clientId, children, type = 'ad', res
|
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
76
|
(0, react_1.useEffect)(() => {
|
|
77
|
-
const keycloak = new keycloak_js_1.default({
|
|
77
|
+
const keycloak = new keycloak_js_1.default({
|
|
78
|
+
url: url,
|
|
79
|
+
realm: realm,
|
|
80
|
+
clientId: clientId,
|
|
81
|
+
});
|
|
78
82
|
setKc(keycloak);
|
|
79
83
|
keycloak
|
|
80
84
|
.init({
|
|
@@ -85,20 +89,25 @@ function KeycloakAuthProvider({ url, realm, clientId, children, type = 'ad', res
|
|
|
85
89
|
setUserLoaded(true);
|
|
86
90
|
if (!auth) {
|
|
87
91
|
console.log('NAO AUTENTICADO');
|
|
92
|
+
//window.location.reload();
|
|
88
93
|
}
|
|
89
94
|
else {
|
|
95
|
+
const tokenParsed = keycloak.tokenParsed;
|
|
96
|
+
console.log('TOKEN-> ', tokenParsed);
|
|
90
97
|
updateUserData(keycloak.token);
|
|
91
98
|
console.info('Authenticated!!!');
|
|
92
99
|
keycloak.onTokenExpired = () => {
|
|
93
|
-
console.log('token expired
|
|
100
|
+
console.log('token expired');
|
|
94
101
|
refreshTokens();
|
|
95
102
|
};
|
|
96
103
|
}
|
|
104
|
+
}, () => {
|
|
105
|
+
console.error('Authenticated Failed');
|
|
97
106
|
})
|
|
98
|
-
.catch((err) =>
|
|
99
|
-
console.error('Authenticated Failed', err);
|
|
100
|
-
});
|
|
107
|
+
.catch((err) => console.log(err));
|
|
101
108
|
const s = router.query['status'];
|
|
109
|
+
if (!s)
|
|
110
|
+
return;
|
|
102
111
|
if (s === 'success') {
|
|
103
112
|
window.history.replaceState(null, '', '/');
|
|
104
113
|
}
|
|
@@ -118,6 +127,6 @@ function KeycloakAuthProvider({ url, realm, clientId, children, type = 'ad', res
|
|
|
118
127
|
setUser(null);
|
|
119
128
|
localStorage.removeItem(userImgName);
|
|
120
129
|
}
|
|
121
|
-
return react_1.default.createElement(
|
|
130
|
+
return react_1.default.createElement(auth_1.AuthContext.Provider, { value: { user, isAuth, userLoaded, login, logout, saveUserData: () => { }, type, refreshTokens } }, children);
|
|
122
131
|
}
|
|
123
132
|
exports.KeycloakAuthProvider = KeycloakAuthProvider;
|
package/package.json
CHANGED