mirror of
https://github.com/khairul169/vaulterm.git
synced 2026-09-15 17:03:30 +07:00
feat: team access control
This commit is contained in:
+14
-2
@@ -2,15 +2,18 @@ import { createStore, useStore } from "zustand";
|
||||
import { persist, createJSONStorage } from "zustand/middleware";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import termSessionStore from "./terminal-sessions";
|
||||
import queryClient from "@/lib/queryClient";
|
||||
|
||||
type AuthStore = {
|
||||
token?: string | null;
|
||||
token: string | null;
|
||||
teamId: string | null;
|
||||
};
|
||||
|
||||
const authStore = createStore(
|
||||
persist<AuthStore>(
|
||||
() => ({
|
||||
token: null,
|
||||
teamId: null,
|
||||
}),
|
||||
{
|
||||
name: "vaulterm:auth",
|
||||
@@ -24,9 +27,18 @@ export const useAuthStore = () => {
|
||||
return { ...state, isLoggedIn: state.token != null };
|
||||
};
|
||||
|
||||
export const setTeam = (teamId: string | null) => {
|
||||
authStore.setState({ teamId });
|
||||
queryClient.invalidateQueries();
|
||||
};
|
||||
|
||||
export const logout = () => {
|
||||
authStore.setState({ token: null });
|
||||
authStore.setState({ token: null, teamId: null });
|
||||
termSessionStore.setState({ sessions: [], curSession: 0 });
|
||||
};
|
||||
|
||||
export const useTeamId = () => {
|
||||
return useStore(authStore, (i) => i.teamId);
|
||||
};
|
||||
|
||||
export default authStore;
|
||||
|
||||
Reference in New Issue
Block a user