Skip to content

Commit

Permalink
fix onGetRequestOK getUser bug
Browse files Browse the repository at this point in the history
  • Loading branch information
prostgles committed Dec 21, 2024
1 parent 35cb1bb commit f258a26
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
13 changes: 10 additions & 3 deletions lib/Auth/setupAuthRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export async function setupAuthRoutes(this: AuthHandler) {
}
return userOrCode;
};
const isLoggedInUser = async () => {
const userInfo = await getUser();
return !!userInfo?.user;
};
if (this.prostgles.restApi) {
if (
Object.values(this.prostgles.restApi.routes).some((restRoute) =>
Expand Down Expand Up @@ -144,7 +148,7 @@ export async function setupAuthRoutes(this: AuthHandler) {
*/
if (this.isUserRoute(req.path)) {
/* Check auth. Redirect to login if unauthorized */
const u = await getUser();
const u = await isLoggedInUser();
if (!u) {
res.redirect(
`${AUTH_ROUTES_AND_PARAMS.login}?returnURL=${encodeURIComponent(req.originalUrl)}`
Expand All @@ -153,12 +157,15 @@ export async function setupAuthRoutes(this: AuthHandler) {
}

/* If authorized and going to returnUrl then redirect. Otherwise serve file */
} else if (returnURL && (await getUser())) {
} else if (returnURL && (await isLoggedInUser())) {
res.redirect(returnURL);
return;

/** If Logged in and requesting login then redirect to main page */
} else if (this.matchesRoute(AUTH_ROUTES_AND_PARAMS.login, req.path) && (await getUser())) {
} else if (
this.matchesRoute(AUTH_ROUTES_AND_PARAMS.login, req.path) &&
(await isLoggedInUser())
) {
res.redirect("/");
return;
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prostgles-server",
"version": "4.2.194",
"version": "4.2.195",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion tests/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f258a26

Please sign in to comment.