Skip to content

Commit 3c7802c

Browse files
mohd-akramdziraf
authored andcommitted
fix: auth route handlers not ending correctly
1 parent a4e3a43 commit 3c7802c

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

src/authentication/login.handler.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const withLogin = (
3030
...providerProps,
3131
});
3232
reply.type('text/html');
33-
reply.send(login);
33+
return reply.send(login);
3434
});
3535

3636
fastifyInstance.post(loginPath, async (req, reply) => {
@@ -60,9 +60,9 @@ export const withLogin = (
6060
req.session.set('adminUser', adminUser);
6161

6262
if (req.session.redirectTo) {
63-
reply.redirect(302, req.session.redirectTo);
63+
return reply.redirect(302, req.session.redirectTo);
6464
} else {
65-
reply.redirect(302, rootPath);
65+
return reply.redirect(302, rootPath);
6666
}
6767
} else {
6868
const login = await admin.renderLogin({
@@ -71,7 +71,7 @@ export const withLogin = (
7171
...providerProps,
7272
});
7373
reply.type('text/html');
74-
reply.send(login);
74+
return reply.send(login);
7575
}
7676
});
7777
};

src/authentication/logout.handler.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@ export const withLogout = (
2020
if (provider) {
2121
await provider.handleLogout({ request, reply });
2222
}
23-
23+
2424
if (request.session) {
25-
request.session.destroy(() => {
26-
reply.redirect(admin.options.loginPath);
27-
})
28-
} else {
29-
reply.redirect(admin.options.loginPath);
25+
await request.session.destroy();
3026
}
27+
return reply.redirect(admin.options.loginPath);
3128
});
3229
};

src/authentication/protected-routes.handler.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const withProtectedRoutesHandler = (
77
): void => {
88
const { rootPath } = admin.options;
99

10-
fastifyApp.addHook('preHandler', async (request, reply) => {
10+
fastifyApp.addHook('preHandler', async (request, reply) => {
1111
const buildComponentRoute = AdminRouter.routes.find((r) => r.action === 'bundleComponents')?.path
1212
if (AdminRouter.assets.find((asset) => request.url.match(asset.path))) {
1313
return;
@@ -28,7 +28,7 @@ export const withProtectedRoutesHandler = (
2828
? rootPath
2929
: redirectTo;
3030

31-
reply.redirect(admin.options.loginPath);
31+
return reply.redirect(admin.options.loginPath);
3232
}
3333
});
3434
};

src/authentication/refresh.handler.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ export const withRefresh = (
5454
};
5555

5656
request.session.set('adminUser', admin);
57-
request.session.save(() => {
58-
reply.send(admin);
59-
});
57+
await request.session.save();
58+
return reply.send(admin);
6059
});
6160
};

0 commit comments

Comments
 (0)