mirror of
https://github.com/aykhans/slash-e.git
synced 2025-07-06 21:22:36 +00:00
chore: user user store
This commit is contained in:
@ -4,6 +4,7 @@ import { toast } from "react-hot-toast";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router-dom";
|
||||
import useNavigateTo from "@/hooks/useNavigateTo";
|
||||
import useUserStore from "@/stores/v1/user";
|
||||
import useWorkspaceStore from "@/stores/v1/workspace";
|
||||
import * as api from "../helpers/api";
|
||||
import useLoading from "../hooks/useLoading";
|
||||
@ -12,6 +13,7 @@ const SignUp: React.FC = () => {
|
||||
const { t } = useTranslation();
|
||||
const navigateTo = useNavigateTo();
|
||||
const workspaceStore = useWorkspaceStore();
|
||||
const userStore = useUserStore();
|
||||
const [email, setEmail] = useState("");
|
||||
const [nickname, setNickname] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
@ -19,8 +21,6 @@ const SignUp: React.FC = () => {
|
||||
const allowConfirm = email.length > 0 && nickname.length > 0 && password.length > 0;
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.removeItem("userId");
|
||||
|
||||
if (!workspaceStore.profile.enableSignup) {
|
||||
return navigateTo("/auth", {
|
||||
replace: true,
|
||||
@ -53,8 +53,9 @@ const SignUp: React.FC = () => {
|
||||
actionBtnLoadingState.setLoading();
|
||||
const { data: user } = await api.signup(email, nickname, password);
|
||||
if (user) {
|
||||
localStorage.setItem("userId", `${user.id}`);
|
||||
window.location.href = "/";
|
||||
userStore.setCurrentUserId(user.id);
|
||||
await userStore.fetchCurrentUser();
|
||||
navigateTo("/");
|
||||
} else {
|
||||
toast.error("Signup failed");
|
||||
}
|
||||
|
Reference in New Issue
Block a user