Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
feat(server): redirect to home for authorized user
Browse files Browse the repository at this point in the history
Co-authored-by: Kenneth Trecy Tobias <19201.tobias.kennethtrecy.c@gmail.com>
  • Loading branch information
lemredd and KennethTrecy committed Oct 13, 2022
1 parent 9807933 commit b0535fd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions routes/enhancer/user/log_in.get.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { Request } from "!/types/dependent"
import type { DocumentProps } from "$/types/server"

import Policy from "!/bases/policy"
import PageMiddleware from "!/bases/controller-likes/page_middleware"
import CommonMiddlewareList from "!/middlewares/common_middleware_list"
import DynamicGatedRedirector from "!/middlewares/miscellaneous/dynamic_gated_redirector"

export default class extends PageMiddleware {
get filePath(): string { return __filename }
Expand All @@ -15,6 +16,9 @@ export default class extends PageMiddleware {
}

get policy(): Policy {
return CommonMiddlewareList.guestOnlyPolicy
return new DynamicGatedRedirector((request: Request) => {
if (request.user === null) return Promise.resolve(null)
return Promise.resolve({ "location": "/" })
}) as unknown as Policy
}
}

0 comments on commit b0535fd

Please sign in to comment.