feat: migrate pocketbase to v0.23
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { Navigate, Outlet } from "react-router-dom";
|
||||
|
||||
import Version from "@/components/Version";
|
||||
import { getPocketBase } from "@/repository/pocketbase";
|
||||
import { getAuthStore } from "@/repository/admin";
|
||||
|
||||
const AuthLayout = () => {
|
||||
const auth = getPocketBase().authStore;
|
||||
if (auth.isValid && auth.isAdmin) {
|
||||
const auth = getAuthStore();
|
||||
if (auth.isValid && auth.isSuperuser) {
|
||||
return <Navigate to="/" />;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import { Button, type ButtonProps, Drawer, Dropdown, Layout, Menu, type MenuProp
|
||||
|
||||
import Version from "@/components/Version";
|
||||
import { useBrowserTheme, useTriggerElement } from "@/hooks";
|
||||
import { getPocketBase } from "@/repository/pocketbase";
|
||||
import { getAuthStore } from "@/repository/admin";
|
||||
|
||||
const ConsoleLayout = () => {
|
||||
const navigate = useNavigate();
|
||||
@@ -35,8 +35,8 @@ const ConsoleLayout = () => {
|
||||
navigate("/settings/account");
|
||||
};
|
||||
|
||||
const auth = getPocketBase().authStore;
|
||||
if (!auth.isValid || !auth.isAdmin) {
|
||||
const auth = getAuthStore();
|
||||
if (!auth.isValid || !auth.isSuperuser) {
|
||||
return <Navigate to="/login" />;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { createSchemaFieldRule } from "antd-zod";
|
||||
import { z } from "zod";
|
||||
|
||||
import { useAntdForm } from "@/hooks";
|
||||
import { getPocketBase } from "@/repository/pocketbase";
|
||||
import { authWithPassword } from "@/repository/admin";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
|
||||
const Login = () => {
|
||||
@@ -27,7 +27,7 @@ const Login = () => {
|
||||
} = useAntdForm<z.infer<typeof formSchema>>({
|
||||
onSubmit: async (values) => {
|
||||
try {
|
||||
await getPocketBase().admins.authWithPassword(values.username, values.password);
|
||||
await authWithPassword(values.username, values.password);
|
||||
await navigage("/");
|
||||
} catch (err) {
|
||||
notificationApi.error({ message: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
|
||||
@@ -6,7 +6,7 @@ import { createSchemaFieldRule } from "antd-zod";
|
||||
import { z } from "zod";
|
||||
|
||||
import { useAntdForm } from "@/hooks";
|
||||
import { getPocketBase } from "@/repository/pocketbase";
|
||||
import { getAuthStore, save as saveAdmin } from "@/repository/admin";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
|
||||
const SettingsAccount = () => {
|
||||
@@ -27,18 +27,16 @@ const SettingsAccount = () => {
|
||||
formProps,
|
||||
} = useAntdForm<z.infer<typeof formSchema>>({
|
||||
initialValues: {
|
||||
username: getPocketBase().authStore.model?.email,
|
||||
username: getAuthStore().record?.email,
|
||||
},
|
||||
onSubmit: async (values) => {
|
||||
try {
|
||||
await getPocketBase().admins.update(getPocketBase().authStore.model?.id, {
|
||||
email: values.username,
|
||||
});
|
||||
await saveAdmin({ email: values.username });
|
||||
|
||||
messageApi.success(t("common.text.operation_succeeded"));
|
||||
|
||||
setTimeout(() => {
|
||||
getPocketBase().authStore.clear();
|
||||
getAuthStore().clear();
|
||||
navigate("/login");
|
||||
}, 500);
|
||||
} catch (err) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { createSchemaFieldRule } from "antd-zod";
|
||||
import { z } from "zod";
|
||||
|
||||
import { useAntdForm } from "@/hooks";
|
||||
import { getPocketBase } from "@/repository/pocketbase";
|
||||
import { authWithPassword, getAuthStore, save as saveAdmin } from "@/repository/admin";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
|
||||
const SettingsPassword = () => {
|
||||
@@ -33,16 +33,13 @@ const SettingsPassword = () => {
|
||||
} = useAntdForm({
|
||||
onSubmit: async (values) => {
|
||||
try {
|
||||
await getPocketBase().admins.authWithPassword(getPocketBase().authStore.model?.email, values.oldPassword);
|
||||
await getPocketBase().admins.update(getPocketBase().authStore.model?.id, {
|
||||
password: values.newPassword,
|
||||
passwordConfirm: values.confirmPassword,
|
||||
});
|
||||
await authWithPassword(getAuthStore().record!.email, values.oldPassword);
|
||||
await saveAdmin({ password: values.newPassword });
|
||||
|
||||
messageApi.success(t("common.text.operation_succeeded"));
|
||||
|
||||
setTimeout(() => {
|
||||
getPocketBase().authStore.clear();
|
||||
getAuthStore().clear();
|
||||
navigate("/login");
|
||||
}, 500);
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user