feat: migrate to vue 3 (#2689)
--------- Co-authored-by: Joep <jcbuhre@gmail.com> Co-authored-by: Omar Hussein <omarmohammad1951@gmail.com> Co-authored-by: Oleg Lobanov <oleg@lobanov.me>
This commit is contained in:
164 files changed
+12202
-8047
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { detectLocale, setLocale } from "@/i18n";
|
||||
import { cloneDeep } from "lodash-es";
|
||||
|
||||
export const useAuthStore = defineStore("auth", {
|
||||
// convert to a function
|
||||
state: (): {
|
||||
user: IUser | null;
|
||||
jwt: string;
|
||||
} => ({
|
||||
user: null,
|
||||
jwt: "",
|
||||
}),
|
||||
getters: {
|
||||
// user and jwt getter removed, no longer needed
|
||||
isLoggedIn: (state) => state.user !== null,
|
||||
},
|
||||
actions: {
|
||||
// no context as first argument, use `this` instead
|
||||
setUser(user: IUser) {
|
||||
if (user === null) {
|
||||
this.user = null;
|
||||
return;
|
||||
}
|
||||
|
||||
setLocale(user.locale || detectLocale());
|
||||
this.user = user;
|
||||
},
|
||||
updateUser(user: Partial<IUser>) {
|
||||
if (user.locale) {
|
||||
setLocale(user.locale);
|
||||
}
|
||||
|
||||
this.user = { ...this.user, ...cloneDeep(user) } as IUser;
|
||||
},
|
||||
// easily reset state using `$reset`
|
||||
clearUser() {
|
||||
this.$reset();
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user