1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-01-25 14:43:42 +02:00
pocketbase/ui/src/routes.js

169 lines
6.4 KiB
JavaScript
Raw Normal View History

2022-08-05 06:00:38 +03:00
import { replace } from "svelte-spa-router";
import { wrap } from "svelte-spa-router/wrap";
import ApiClient from "@/utils/ApiClient";
import PageIndex from "@/components/PageIndex.svelte";
import PageLogs from "@/components/logs/PageLogs.svelte";
import PageRecords from "@/components/records/PageRecords.svelte";
import PageAdmins from "@/components/admins/PageAdmins.svelte";
import PageAdminLogin from "@/components/admins/PageAdminLogin.svelte";
import PageApplication from "@/components/settings/PageApplication.svelte";
import PageMail from "@/components/settings/PageMail.svelte";
import PageStorage from "@/components/settings/PageStorage.svelte";
import PageAuthProviders from "@/components/settings/PageAuthProviders.svelte";
import PageTokenOptions from "@/components/settings/PageTokenOptions.svelte";
import PageExportCollections from "@/components/settings/PageExportCollections.svelte";
import PageImportCollections from "@/components/settings/PageImportCollections.svelte";
2023-05-13 22:10:14 +03:00
import PageBackups from "@/components/settings/PageBackups.svelte";
2022-07-07 00:19:05 +03:00
const baseConditions = [
async (details) => {
const realQueryParams = new URLSearchParams(window.location.search);
if (details.location !== "/" && realQueryParams.has(import.meta.env.PB_INSTALLER_PARAM)) {
return replace("/")
}
2022-07-07 00:19:05 +03:00
return true
}
];
const routes = {
2022-07-07 00:19:05 +03:00
"/login": wrap({
component: PageAdminLogin,
2022-08-02 17:00:14 +03:00
conditions: baseConditions.concat([(_) => !ApiClient.authStore.isValid]),
userData: { showAppSidebar: false },
2022-07-07 00:19:05 +03:00
}),
"/request-password-reset": wrap({
asyncComponent: () => import("@/components/admins/PageAdminRequestPasswordReset.svelte"),
2022-08-02 17:00:14 +03:00
conditions: baseConditions.concat([(_) => !ApiClient.authStore.isValid]),
userData: { showAppSidebar: false },
2022-07-07 00:19:05 +03:00
}),
"/confirm-password-reset/:token": wrap({
asyncComponent: () => import("@/components/admins/PageAdminConfirmPasswordReset.svelte"),
2022-08-02 17:00:14 +03:00
conditions: baseConditions.concat([(_) => !ApiClient.authStore.isValid]),
userData: { showAppSidebar: false },
2022-07-07 00:19:05 +03:00
}),
"/collections": wrap({
component: PageRecords,
2022-08-02 17:00:14 +03:00
conditions: baseConditions.concat([(_) => ApiClient.authStore.isValid]),
userData: { showAppSidebar: true },
2022-07-07 00:19:05 +03:00
}),
"/logs": wrap({
component: PageLogs,
2022-08-02 17:00:14 +03:00
conditions: baseConditions.concat([(_) => ApiClient.authStore.isValid]),
userData: { showAppSidebar: true },
2022-07-07 00:19:05 +03:00
}),
"/settings": wrap({
component: PageApplication,
2022-08-02 17:00:14 +03:00
conditions: baseConditions.concat([(_) => ApiClient.authStore.isValid]),
userData: { showAppSidebar: true },
2022-07-07 00:19:05 +03:00
}),
"/settings/admins": wrap({
component: PageAdmins,
2022-08-02 17:00:14 +03:00
conditions: baseConditions.concat([(_) => ApiClient.authStore.isValid]),
userData: { showAppSidebar: true },
2022-07-07 00:19:05 +03:00
}),
"/settings/mail": wrap({
component: PageMail,
2022-08-02 17:00:14 +03:00
conditions: baseConditions.concat([(_) => ApiClient.authStore.isValid]),
userData: { showAppSidebar: true },
2022-07-07 00:19:05 +03:00
}),
"/settings/storage": wrap({
component: PageStorage,
2022-08-02 17:00:14 +03:00
conditions: baseConditions.concat([(_) => ApiClient.authStore.isValid]),
userData: { showAppSidebar: true },
2022-07-07 00:19:05 +03:00
}),
"/settings/auth-providers": wrap({
component: PageAuthProviders,
2022-08-02 17:00:14 +03:00
conditions: baseConditions.concat([(_) => ApiClient.authStore.isValid]),
userData: { showAppSidebar: true },
2022-07-07 00:19:05 +03:00
}),
"/settings/tokens": wrap({
component: PageTokenOptions,
2022-08-02 17:00:14 +03:00
conditions: baseConditions.concat([(_) => ApiClient.authStore.isValid]),
userData: { showAppSidebar: true },
2022-07-07 00:19:05 +03:00
}),
2022-08-05 06:00:38 +03:00
"/settings/export-collections": wrap({
component: PageExportCollections,
conditions: baseConditions.concat([(_) => ApiClient.authStore.isValid]),
userData: { showAppSidebar: true },
}),
"/settings/import-collections": wrap({
component: PageImportCollections,
conditions: baseConditions.concat([(_) => ApiClient.authStore.isValid]),
userData: { showAppSidebar: true },
}),
2023-05-13 22:10:14 +03:00
"/settings/backups": wrap({
component: PageBackups,
conditions: baseConditions.concat([(_) => ApiClient.authStore.isValid]),
userData: { showAppSidebar: true },
}),
2022-08-05 06:00:38 +03:00
2022-10-30 10:28:14 +02:00
// ---------------------------------------------------------------
// Records email confirmation actions
// ---------------------------------------------------------------
// @deprecated
"/users/confirm-password-reset/:token": wrap({
asyncComponent: () => import("@/components/records/PageRecordConfirmPasswordReset.svelte"),
conditions: baseConditions,
userData: { showAppSidebar: false },
}),
"/auth/confirm-password-reset/:token": wrap({
asyncComponent: () => import("@/components/records/PageRecordConfirmPasswordReset.svelte"),
conditions: baseConditions,
userData: { showAppSidebar: false },
}),
// @deprecated
"/users/confirm-verification/:token": wrap({
asyncComponent: () => import("@/components/records/PageRecordConfirmVerification.svelte"),
conditions: baseConditions,
userData: { showAppSidebar: false },
}),
"/auth/confirm-verification/:token": wrap({
asyncComponent: () => import("@/components/records/PageRecordConfirmVerification.svelte"),
conditions: baseConditions,
userData: { showAppSidebar: false },
}),
// @deprecated
"/users/confirm-email-change/:token": wrap({
asyncComponent: () => import("@/components/records/PageRecordConfirmEmailChange.svelte"),
conditions: baseConditions,
userData: { showAppSidebar: false },
}),
"/auth/confirm-email-change/:token": wrap({
asyncComponent: () => import("@/components/records/PageRecordConfirmEmailChange.svelte"),
conditions: baseConditions,
userData: { showAppSidebar: false },
}),
"/auth/oauth2-redirect": wrap({
asyncComponent: () => import("@/components/records/PageOAuth2Redirect.svelte"),
conditions: baseConditions,
userData: { showAppSidebar: false },
}),
2022-10-30 10:28:14 +02:00
// catch-all fallback
2022-07-07 00:19:05 +03:00
"*": wrap({
component: PageIndex,
userData: { showAppSidebar: false },
2022-07-07 00:19:05 +03:00
}),
};
export default routes;