Skip to content

Commit

Permalink
feat: auto redirect to home page if password and auth_secret arent set
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-shuman committed Sep 10, 2024
1 parent 9f19273 commit cd0e5a9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/routes/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export const load: LayoutServerLoad = async ({ cookies }) => {
return redirect(302, '/login');
}

return { authCookie: cookies.get('auth') };
return { authCookie: cookies.get('auth'), usesAuth: Boolean(env.PASSWORD) };
};
6 changes: 4 additions & 2 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@
<IconButton icon="tabler:rss" href="/rss.xml" />
<IconButton icon="tabler:atom" href="/atom" />
<IconButton icon="tabler:json" href="/json" />
<span>•</span>
<IconButton icon="tabler:logout" href="/logout" />
{#if data.usesAuth}
<span>•</span>
<IconButton icon="tabler:logout" href="/logout" />
{/if}
</div>
</section>
</header>
Expand Down
4 changes: 4 additions & 0 deletions src/routes/login/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { fail, redirect } from '@sveltejs/kit';
import { SignJWT } from 'jose';

export const load = async ({ cookies }) => {
if (!env.PASSWORD) {
return redirect(303, '/');
}

const authCookie = cookies.get('auth');

if (authCookie) {
Expand Down
5 changes: 5 additions & 0 deletions src/routes/logout/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { env } from '$env/dynamic/private';
import { redirect } from '@sveltejs/kit';

export const load = ({ cookies }) => {
if (!env.PASSWORD) {
return redirect(303, '/');
}

cookies.delete('auth', { path: '/' });
return redirect(303, '/login');
};

0 comments on commit cd0e5a9

Please sign in to comment.