Skip to content

Commit

Permalink
Add start to auth ui
Browse files Browse the repository at this point in the history
  • Loading branch information
CannonLock committed Dec 14, 2023
1 parent f18c260 commit c5a57aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/security/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export const secureFetch = async (url, options) => {
const response = await fetch(url, options);

if (response.status === 401 || response.status === 403) {
window.open(`${import.meta.env.VITE_MACROSTRAT_INGEST_API}/security/login`, '_blank').focus();

const url = new URL(`${import.meta.env.VITE_MACROSTRAT_INGEST_API}/security/login`);
url.searchParams.append("return_url", `${window.location.origin}/dev/security/endpoint`);

window.open(url, '_blank').focus();
throw {name: "UnauthorizedError", message: "User is not logged in"}
}

Expand Down
9 changes: 9 additions & 0 deletions src/pages/dev/security/endpoint/index.page.ts
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("span", "You are logged in, you can now close this tab.")
]);
}

4 changes: 2 additions & 2 deletions src/pages/dev/security/index.page.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const guard = (pageContext) => {
throw redirect('/login')
*/
}
if (!user.groups.includes("admin")) {
if (!user.groups.includes(1)) {
// Render the error page and show message to the user
throw render(403, 'Only admins are allowed to access this page.')
return render(403, 'Only admins are allowed to access this page.')
}
}

0 comments on commit c5a57aa

Please sign in to comment.