mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-09-22 12:20:10 +02:00
91f5f94200
* multi user wip * WIP MUM features * invitation mgmt * suspend or unsuspend users * workspace mangement * manage chats * manage chats * add Support for admin system settings for users to delete workspaces and limit chats per user * fix issue ith system var update app to lazy load invite page * cleanup and bug fixes * wrong method * update readme * update readme * update readme * bump version to 0.1.0
32 lines
994 B
JavaScript
32 lines
994 B
JavaScript
import React, { useState, createContext } from "react";
|
|
import { AUTH_TOKEN, AUTH_USER } from "./utils/constants";
|
|
|
|
export const AuthContext = createContext(null);
|
|
export function ContextWrapper(props) {
|
|
const localUser = localStorage.getItem(AUTH_USER);
|
|
const localAuthToken = localStorage.getItem(AUTH_TOKEN);
|
|
const [store, setStore] = useState({
|
|
user: localUser ? JSON.parse(localUser) : null,
|
|
authToken: localAuthToken ? localAuthToken : null,
|
|
});
|
|
|
|
const [actions] = useState({
|
|
updateUser: (user, authToken = "") => {
|
|
localStorage.setItem(AUTH_USER, JSON.stringify(user));
|
|
localStorage.setItem(AUTH_TOKEN, authToken);
|
|
setStore({ user, authToken });
|
|
},
|
|
unsetUser: () => {
|
|
localStorage.removeItem(AUTH_USER);
|
|
localStorage.removeItem(AUTH_TOKEN);
|
|
setStore({ user: null, authToken: null });
|
|
},
|
|
});
|
|
|
|
return (
|
|
<AuthContext.Provider value={{ store, actions }}>
|
|
{props.children}
|
|
</AuthContext.Provider>
|
|
);
|
|
}
|