@raketa-cloud/admin 0.0.75 → 0.0.76
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 +1 -1
- package/src/setupAuthentication.js +12 -6
package/package.json
CHANGED
|
@@ -6,13 +6,17 @@ import AuthHelper from "./helpers/AuthHelper";
|
|
|
6
6
|
function getAuthBearer(c) {
|
|
7
7
|
const authHeader = c.req.header("Authorization") || "";
|
|
8
8
|
|
|
9
|
-
return authHeader.replace("Bearer
|
|
9
|
+
return authHeader.replace("Bearer", "").trim();
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const setupAuthentication = (app, config) => {
|
|
13
13
|
app.use(async (c, next) => {
|
|
14
14
|
const token = getCookie(c, AuthHelper.cookie_key) || getAuthBearer(c);
|
|
15
15
|
|
|
16
|
+
if (!token) {
|
|
17
|
+
return c.redirect("/login");
|
|
18
|
+
}
|
|
19
|
+
|
|
16
20
|
const status = AuthHelper.isAuthenticated({ path: c.req.path, token });
|
|
17
21
|
|
|
18
22
|
if (!status) {
|
|
@@ -67,7 +71,6 @@ const setupAuthentication = (app, config) => {
|
|
|
67
71
|
|
|
68
72
|
app.get("/logout", (c) => {
|
|
69
73
|
deleteCookie(c, AuthHelper.cookie_key);
|
|
70
|
-
deleteCookie(c, config.remoteConfig.cookie_key);
|
|
71
74
|
return c.redirect("/login");
|
|
72
75
|
});
|
|
73
76
|
|
|
@@ -94,13 +97,16 @@ const setupAuthentication = (app, config) => {
|
|
|
94
97
|
app.get("/profile", (c) => {
|
|
95
98
|
const token = getAuthBearer(c);
|
|
96
99
|
|
|
97
|
-
// TODO: Here we may update the Gateway API to have the check
|
|
100
|
+
// TODO: Here we may update the Gateway API to have the check dynamically done in the backend!
|
|
98
101
|
if (AuthHelper.verifyJWT(token)) {
|
|
99
|
-
c.res.status = 200;
|
|
100
102
|
return c.json({ message: "OK" });
|
|
101
103
|
} else {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
+
return new Response("Unauthorized", {
|
|
105
|
+
status: 401,
|
|
106
|
+
headers: {
|
|
107
|
+
Authenticate: 'error="invalid_token"',
|
|
108
|
+
},
|
|
109
|
+
});
|
|
104
110
|
}
|
|
105
111
|
});
|
|
106
112
|
};
|