add user-auth and init-session events
This commit is contained in:
parent
fe954f2960
commit
ea3fc85371
8 changed files with 174 additions and 77 deletions
34
src/modules/auth.ts
Normal file
34
src/modules/auth.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
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
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue