Compare commits
4 Commits
svelte5
...
better-aut
Author | SHA1 | Date | |
---|---|---|---|
eadb567069
|
|||
7d6226d79a
|
|||
28367293e8
|
|||
9b77640977
|
@@ -12,7 +12,9 @@ async function authorization({ event, resolve }) {
|
|||||||
if (event.url.pathname.startsWith('/rezepte/edit') || event.url.pathname.startsWith('/rezepte/add')) {
|
if (event.url.pathname.startsWith('/rezepte/edit') || event.url.pathname.startsWith('/rezepte/add')) {
|
||||||
const session = await event.locals.auth();
|
const session = await event.locals.auth();
|
||||||
if (!session) {
|
if (!session) {
|
||||||
redirect(303, '/auth/signin');
|
// Preserve the original URL the user was trying to access
|
||||||
|
const callbackUrl = encodeURIComponent(event.url.pathname + event.url.search);
|
||||||
|
redirect(303, `/login?callbackUrl=${callbackUrl}`);
|
||||||
}
|
}
|
||||||
else if (! session.user.groups.includes('rezepte_users')) {
|
else if (! session.user.groups.includes('rezepte_users')) {
|
||||||
// strip last dir from url
|
// strip last dir from url
|
||||||
|
@@ -139,10 +139,10 @@ h2 + p{
|
|||||||
<p>({user.nickname})</p>
|
<p>({user.nickname})</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="https://sso.bocken.org/if/user/#/settings" >Einstellungen</a></li>
|
<li><a href="https://sso.bocken.org/if/user/#/settings" >Einstellungen</a></li>
|
||||||
<li><a href="/auth/signout" >Log Out</a></li>
|
<li><a href="/logout" >Log Out</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
{:else}
|
{:else}
|
||||||
<a class=entry href=/auth/signin>Log In</a>
|
<a class=entry href=/login>Log In</a>
|
||||||
{/if}
|
{/if}
|
||||||
|
@@ -1,3 +0,0 @@
|
|||||||
import { signIn } from "../../../auth"
|
|
||||||
import type { Actions } from "./$types"
|
|
||||||
export const actions: Actions = { default: signIn }
|
|
@@ -1,3 +0,0 @@
|
|||||||
import { signIn } from "../../../auth"
|
|
||||||
import type { Actions } from "./$types"
|
|
||||||
export const actions: Actions = { default: signIn }
|
|
44
src/routes/login/+server.ts
Normal file
44
src/routes/login/+server.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import type { RequestHandler } from './$types';
|
||||||
|
|
||||||
|
export const GET: RequestHandler = async ({ url }) => {
|
||||||
|
const callbackUrl = url.searchParams.get('callbackUrl') || '/';
|
||||||
|
|
||||||
|
// Create a minimal page with site styling that immediately triggers auth
|
||||||
|
const html = `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Login</title>
|
||||||
|
<style>
|
||||||
|
:root{
|
||||||
|
--nord0: #2E3440;
|
||||||
|
--nord1: #3B4252;
|
||||||
|
--nord4: #D8DEE9;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
background-color: var(--nord1);
|
||||||
|
color: var(--nord4);
|
||||||
|
font-family: sans-serif;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form id="signin-form" method="POST" action="/auth/signin/authentik">
|
||||||
|
<input type="hidden" name="callbackUrl" value="${callbackUrl}" />
|
||||||
|
</form>
|
||||||
|
<script>
|
||||||
|
// Immediately submit the form to trigger auth flow
|
||||||
|
document.getElementById('signin-form').submit();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>`;
|
||||||
|
|
||||||
|
return new Response(html, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'text/html'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
44
src/routes/logout/+server.ts
Normal file
44
src/routes/logout/+server.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import type { RequestHandler } from './$types';
|
||||||
|
|
||||||
|
export const GET: RequestHandler = async ({ url }) => {
|
||||||
|
const callbackUrl = url.searchParams.get('callbackUrl') || '/';
|
||||||
|
|
||||||
|
// Create a minimal page with site styling that immediately triggers logout
|
||||||
|
const html = `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Logout</title>
|
||||||
|
<style>
|
||||||
|
:root{
|
||||||
|
--nord0: #2E3440;
|
||||||
|
--nord1: #3B4252;
|
||||||
|
--nord4: #D8DEE9;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
background-color: var(--nord1);
|
||||||
|
color: var(--nord4);
|
||||||
|
font-family: sans-serif;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form id="signout-form" method="POST" action="/auth/signout">
|
||||||
|
<input type="hidden" name="callbackUrl" value="${callbackUrl}" />
|
||||||
|
</form>
|
||||||
|
<script>
|
||||||
|
// Immediately submit the form to trigger logout flow
|
||||||
|
document.getElementById('signout-form').submit();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>`;
|
||||||
|
|
||||||
|
return new Response(html, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'text/html'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
Reference in New Issue
Block a user