@raketa-cloud/admin 0.0.74 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raketa-cloud/admin",
3
- "version": "0.0.74",
3
+ "version": "0.0.76",
4
4
  "main": "src/index.js",
5
5
  "scripts": {
6
6
  "dev": "npx tailwindcss -i ./src/styles/application.css -o ../../apps/admin/static/application.css --watch",
@@ -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
 
@@ -79,26 +82,31 @@ const setupAuthentication = (app, config) => {
79
82
  return c.redirect("/login");
80
83
  }
81
84
 
82
- setCookie(c, config.remoteConfig.cookie_key, token, {
83
- path: "/",
84
- httpOnly: true,
85
- secure: true,
86
- domain: config.remoteConfig.domain,
87
- });
88
-
89
- return c.redirect([config.remoteConfig.host, c.req.query().redirect_to].join(""));
85
+ // TODO: Figure out how to change this so it is secure!
86
+ return c.redirect(
87
+ [
88
+ config.remoteConfig.remoteLogin,
89
+ "?redirect_to=",
90
+ c.req.query().redirect_to,
91
+ "&page_snapshot=",
92
+ token,
93
+ ].join("")
94
+ );
90
95
  });
91
96
 
92
97
  app.get("/profile", (c) => {
93
98
  const token = getAuthBearer(c);
94
99
 
95
- // TODO: Here we may update the Gateway API to have the check dinamically done in the backend!
100
+ // TODO: Here we may update the Gateway API to have the check dynamically done in the backend!
96
101
  if (AuthHelper.verifyJWT(token)) {
97
- c.res.status = 200;
98
102
  return c.json({ message: "OK" });
99
103
  } else {
100
- c.res.status = 401;
101
- return c.res.json({ message: "Unauthorized" });
104
+ return new Response("Unauthorized", {
105
+ status: 401,
106
+ headers: {
107
+ Authenticate: 'error="invalid_token"',
108
+ },
109
+ });
102
110
  }
103
111
  });
104
112
  };