-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6255704
commit b5fcab8
Showing
5 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { render, redirect } from 'vite-plugin-ssr/abort' | ||
|
||
export const guard = (pageContext) => { | ||
const { user } = pageContext | ||
|
||
console.log("User: ", user) | ||
|
||
if (user === undefined) { | ||
// Render the login page while preserving the URL. (This is novel technique | ||
// which we explain down below.) | ||
throw redirect(`${import.meta.env.VITE_MACROSTRAT_INGEST_API}/security/login?return_url=${pageContext.url}`) | ||
/* The more traditional way, redirect the user: | ||
throw redirect('/login') | ||
*/ | ||
} | ||
if (!user.groups.includes("admin")) { | ||
// Render the error page and show message to the user | ||
throw render(403, 'Only admins are allowed to access this page.') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {default as h} from "@macrostrat/hyper"; | ||
|
||
export function Page() { | ||
|
||
return h("div", [ | ||
h("h1", "Secure Page") | ||
]); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters