Skip to content

Commit ecf9f3d

Browse files
committed
Replace secure-session with session
1 parent 74ec81c commit ecf9f3d

File tree

5 files changed

+36
-138
lines changed

5 files changed

+36
-138
lines changed

package-lock.json

Lines changed: 21 additions & 115 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
},
2222
"dependencies": {
2323
"@apollo/client": "^3.13.6",
24+
"@fastify/autoload": "^6.3.0",
25+
"@fastify/cookie": "^11.0.2",
26+
"@fastify/env": "^5.0.2",
27+
"@fastify/http-proxy": "^11.1.2",
28+
"@fastify/sensible": "^6.0.3",
29+
"@fastify/session": "^11.1.0",
30+
"@fastify/static": "^8.1.1",
31+
"@fastify/vite": "^8.1.3",
2432
"@hookform/resolvers": "^5.0.0",
2533
"@ui5/webcomponents": "^2.7.2",
2634
"@ui5/webcomponents-fiori": "^2.7.2",
@@ -30,14 +38,6 @@
3038
"dotenv": "^16.5.0",
3139
"fastify": "^5.3.3",
3240
"fastify-plugin": "^5.0.1",
33-
"@fastify/autoload": "^6.3.0",
34-
"@fastify/cookie": "^11.0.2",
35-
"@fastify/env": "^5.0.2",
36-
"@fastify/http-proxy": "^11.1.2",
37-
"@fastify/secure-session": "^8.2.0",
38-
"@fastify/sensible": "^6.0.3",
39-
"@fastify/static": "^8.1.1",
40-
"@fastify/vite": "^8.1.3",
4141
"graphql": "^16.10.0",
4242
"graphql-config": "^5.1.3",
4343
"i18next": "^25.0.0",

server/plugins/http-proxy.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import fp from "fastify-plugin";
22
import httpProxy from "@fastify/http-proxy";
3-
import { COOKIE_NAME_ONBOARDING } from "./secure-session.js";
43
import { AuthenticationError } from "./auth-utils.js";
54

65
function proxyPlugin(fastify) {
@@ -35,8 +34,7 @@ function proxyPlugin(fastify) {
3534
const refreshToken = request.session.get("refreshToken");
3635
if (!refreshToken) {
3736
request.log.error("Missing refresh token; deleting session.");
38-
request.session.delete();
39-
reply.clearCookie(COOKIE_NAME_ONBOARDING, { path: "/" });
37+
request.session.destroy();
4038
return reply.unauthorized("Session expired without token refresh capability.");
4139
}
4240

@@ -50,8 +48,7 @@ function proxyPlugin(fastify) {
5048
}, issuerConfiguration.tokenEndpoint);
5149
if (!refreshedTokenData || !refreshedTokenData.accessToken) {
5250
request.log.error("Token refresh failed (no access token); deleting session.");
53-
request.session.delete();
54-
reply.clearCookie(COOKIE_NAME_ONBOARDING, { path: "/" });
51+
request.session.destroy();
5552
return reply.unauthorized("Session expired and token refresh failed.");
5653
}
5754

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
import secureSession from "@fastify/secure-session";
1+
import fastifySession from "@fastify/session";
22
import fp from "fastify-plugin";
33
import fastifyCookie from "@fastify/cookie";
44

55

6-
export const COOKIE_NAME_ONBOARDING = "onboarding";
7-
86
async function secureSessionPlugin(fastify) {
97
const { COOKIE_SECRET, NODE_ENV } = fastify.config;
108

119
await fastify.register(fastifyCookie);
1210

13-
fastify.register(secureSession, {
14-
secret: Buffer.from(COOKIE_SECRET, "hex"),
15-
cookieName: COOKIE_NAME_ONBOARDING,
11+
fastify.register(fastifySession, {
12+
secret: COOKIE_SECRET,
1613
cookie: {
1714
path: "/",
1815
httpOnly: true,

server/routes/auth.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import fp from "fastify-plugin";
2-
import { COOKIE_NAME_ONBOARDING } from "../plugins/secure-session.js";
32
import { AuthenticationError } from "../plugins/auth-utils.js";
43

54

@@ -62,10 +61,9 @@ async function authPlugin(fastify) {
6261
});
6362

6463

65-
fastify.post("/auth/logout", async (_req, reply) => {
64+
fastify.post("/auth/logout", async (req, reply) => {
6665
// TODO: Idp sign out flow
67-
//_req.session.delete(); // remove payload
68-
reply.clearCookie(COOKIE_NAME_ONBOARDING, { path: "/" });
66+
req.session.destroy();
6967
reply.send({ message: "Logged out" });
7068
});
7169
}

0 commit comments

Comments
 (0)