mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
refactor: first load redirection
This commit is contained in:
+27
-21
@@ -7,7 +7,6 @@
|
||||
import { reportWebVitals } from '$lib/helpers/vitals';
|
||||
import { Notifications, Progress } from '$lib/layout';
|
||||
import { app } from '$lib/stores/app';
|
||||
import { user } from '$lib/stores/user';
|
||||
import { ENV, isCloud } from '$lib/system';
|
||||
import * as Sentry from '@sentry/svelte';
|
||||
import LogRocket from 'logrocket';
|
||||
@@ -17,6 +16,7 @@
|
||||
import { loading, requestedMigration } from './store';
|
||||
import { parseIfString } from '$lib/helpers/object';
|
||||
import Consent, { consent } from '$lib/components/consent.svelte';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
|
||||
if (browser) {
|
||||
window.VERCEL_ANALYTICS_ID = import.meta.env.VERCEL_ANALYTICS_ID?.toString() ?? false;
|
||||
@@ -64,37 +64,43 @@
|
||||
/**
|
||||
* Handle initial load.
|
||||
*/
|
||||
if (!$page.url.pathname.startsWith('/auth') && !$page.url.pathname.startsWith('/git')) {
|
||||
const acceptedRoutes = [
|
||||
'/login',
|
||||
'/register',
|
||||
'/recover',
|
||||
'/invite',
|
||||
'/card',
|
||||
'/hackathon'
|
||||
];
|
||||
if ($user) {
|
||||
if (
|
||||
!$page.url.pathname.startsWith('/console') &&
|
||||
!$page.url.pathname.startsWith('/invite') &&
|
||||
!$page.url.pathname.startsWith('/card') &&
|
||||
!$page.url.pathname.startsWith('/hackathon')
|
||||
) {
|
||||
|
||||
function shouldRedirect(route: string, routes: string[]) {
|
||||
return !routes.some((n) => route.startsWith(n));
|
||||
}
|
||||
|
||||
const authenticationRoutes = ['/auth', '/git'];
|
||||
const acceptedUnauthenticatedRoutes = [
|
||||
'/login',
|
||||
'/register',
|
||||
'/recover',
|
||||
'/invite',
|
||||
'/card',
|
||||
'/hackathon',
|
||||
'/test'
|
||||
];
|
||||
const acceptedAuthenticatedRoutes = ['/console', '/invite', '/card', '/hackathon'];
|
||||
|
||||
const pathname = $page.url.pathname;
|
||||
const user = $page.data.account as Models.User<Record<string, string>>;
|
||||
|
||||
if (shouldRedirect(pathname, authenticationRoutes)) {
|
||||
if (user?.$id) {
|
||||
if (shouldRedirect(pathname, acceptedAuthenticatedRoutes)) {
|
||||
await goto(`${base}/console`, {
|
||||
replaceState: true
|
||||
});
|
||||
}
|
||||
loading.set(false);
|
||||
} else {
|
||||
if (acceptedRoutes.some((n) => $page.url.pathname.startsWith(n))) {
|
||||
await goto(`${base}${$page.url.pathname}${$page.url.search}`);
|
||||
if (acceptedUnauthenticatedRoutes.some((n) => pathname.startsWith(n))) {
|
||||
await goto(`${base}${pathname}${$page.url.search}`);
|
||||
} else {
|
||||
await goto(`${base}/login`, {
|
||||
replaceState: true
|
||||
});
|
||||
}
|
||||
loading.set(false);
|
||||
}
|
||||
loading.set(false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+2
-1
@@ -13,7 +13,8 @@ const config = defineConfig({
|
||||
'@analytics/google-analytics',
|
||||
'analytics',
|
||||
'dayjs',
|
||||
'dotenv'
|
||||
'dotenv',
|
||||
'zrender'
|
||||
]
|
||||
},
|
||||
define: {
|
||||
|
||||
Reference in New Issue
Block a user