mime-chat/src/modules/auth.ts
2021-05-25 09:01:28 -05:00

34 lines
580 B
TypeScript

import { ref, Ref} from "vue";
interface UserState {
email: string | null;
password?: string;
key: string | null;
}
const user:Ref<UserState> = ref({
email: null,
key: "testing"
});
const CRIMATA_KEY = "CRIMATA_KEY";
const raw = window.localStorage.getItem(CRIMATA_KEY);
if (raw) {
user.value = JSON.parse(raw);
}
export const useAuth = () => {
const setUser = (token: UserState) => {
window.localStorage.setItem(CRIMATA_KEY, JSON.stringify(token));
user.value = token;
}
return {
setUser,
user
}
}