Skip to content

Commit

Permalink
fix: auth route handlers not ending correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
mohd-akram authored and dziraf committed Mar 4, 2024
1 parent a4e3a43 commit 3c7802c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/authentication/login.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const withLogin = (
...providerProps,
});
reply.type('text/html');
reply.send(login);
return reply.send(login);
});

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

if (req.session.redirectTo) {
reply.redirect(302, req.session.redirectTo);
return reply.redirect(302, req.session.redirectTo);
} else {
reply.redirect(302, rootPath);
return reply.redirect(302, rootPath);
}
} else {
const login = await admin.renderLogin({
Expand All @@ -71,7 +71,7 @@ export const withLogin = (
...providerProps,
});
reply.type('text/html');
reply.send(login);
return reply.send(login);
}
});
};
9 changes: 3 additions & 6 deletions src/authentication/logout.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ export const withLogout = (
if (provider) {
await provider.handleLogout({ request, reply });
}

if (request.session) {
request.session.destroy(() => {
reply.redirect(admin.options.loginPath);
})
} else {
reply.redirect(admin.options.loginPath);
await request.session.destroy();
}
return reply.redirect(admin.options.loginPath);
});
};
4 changes: 2 additions & 2 deletions src/authentication/protected-routes.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const withProtectedRoutesHandler = (
): void => {
const { rootPath } = admin.options;

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

reply.redirect(admin.options.loginPath);
return reply.redirect(admin.options.loginPath);
}
});
};
5 changes: 2 additions & 3 deletions src/authentication/refresh.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ export const withRefresh = (
};

request.session.set('adminUser', admin);
request.session.save(() => {
reply.send(admin);
});
await request.session.save();
return reply.send(admin);
});
};

0 comments on commit 3c7802c

Please sign in to comment.