refactor: authentication on public routes (#6765)

* refactor: authentication on public routes

* fix: remove public user

* pr feedback

* pr feedback

* pr feedback

* pr feedback

* remove unused method

* fix: tests

* fix: useless methods

* fix: tests

* pr feedback

* pr feedback

* chore: cleanup

---------

Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
martin
2024-02-13 02:47:26 +01:00
committed by GitHub
parent 45ea0bb689
commit f1e4fdf175
16 changed files with 92 additions and 75 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
import { getAuthUser } from '$lib/utils/auth';
import { authenticate } from '$lib/utils/auth';
import { api, ThumbnailFormat } from '@api';
import type { AxiosError } from 'axios';
import type { PageLoad } from './$types';
@@ -6,7 +6,7 @@ import { error as throwError } from '@sveltejs/kit';
export const load = (async ({ params }) => {
const { key } = params;
await getAuthUser();
await authenticate({ public: true });
try {
const { data: sharedLink } = await api.sharedLinkApi.getMySharedLink({ key });
+2 -2
View File
@@ -1,14 +1,14 @@
import { AppRoute } from '$lib/constants';
import { redirect } from '@sveltejs/kit';
import { api } from '../api';
import { isLoggedIn } from '../lib/utils/auth';
import { loadUser } from '../lib/utils/auth';
import type { PageLoad } from './$types';
export const ssr = false;
export const csr = true;
export const load = (async () => {
const authenticated = await isLoggedIn();
const authenticated = await loadUser();
if (authenticated) {
redirect(302, AppRoute.PHOTOS);
}
+3 -2
View File
@@ -2,11 +2,12 @@ import { AppRoute } from '$lib/constants';
import { authenticate } from '$lib/utils/auth';
import { redirect } from '@sveltejs/kit';
import type { PageLoad } from './$types';
import { getSavedUser } from '$lib/stores/user.store';
import { get } from 'svelte/store';
import { user } from '$lib/stores/user.store';
export const load = (async () => {
await authenticate();
if (!getSavedUser().shouldChangePassword) {
if (!get(user).shouldChangePassword) {
redirect(302, AppRoute.PHOTOS);
}