Fix registration not displaying #14

Merged
jacob1123 merged 5 commits from registration into master 2022-02-22 14:44:29 +01:00
3 changed files with 47 additions and 64 deletions
Showing only changes of commit e9d4ed1b3e - Show all commits

View File

@ -5,6 +5,7 @@ import { useSessionStore } from "../stores/session";
const error = ref("");
const login = ref({ user: "", password: "" });
const router = useRouter(); // has to be called in setup
onMounted(() => {
useSessionStore().setTitle("Login");
@ -15,7 +16,8 @@ function formSubmit(e: MouseEvent) {
useSessionStore().login(login.value)
.then(x => {
error.value = "";
useRouter().replace("/dashboard");
router.replace("/dashboard");
return x;
})
.catch(x => error.value = "The entered credentials are invalid!");

View File

@ -20,12 +20,12 @@ export interface Budget {
export const useSessionStore = defineStore('session', {
state: () => ({
Session: useStorage<Session>('session', null, undefined, { serializer: StorageSerializers.object }),
Session: useStorage<Session | null>('session', null, undefined, { serializer: StorageSerializers.object }),
Budgets: useStorage<Map<string, Budget>>('budgets', new Map<string, Budget>(), undefined, { serializer: StorageSerializers.map }),
}),
getters: {
BudgetsList: (state) => [ ...state.Budgets.values() ],
AuthHeaders: (state) => ({'Authorization': 'Bearer ' + state.Session.Token}),
AuthHeaders: (state) => ({'Authorization': 'Bearer ' + state.Session?.Token}),
LoggedIn: (state) => state.Session != null,
},
actions: {
@ -42,15 +42,18 @@ export const useSessionStore = defineStore('session', {
async login(login: any) {
const response = await POST("/user/login", JSON.stringify(login));
const result = await response.json();
return this.loginSuccess(result);
this.loginSuccess(result);
return result;
},
async register(login : any) {
const response = await POST("/user/register", JSON.stringify(login));
const result = await response.json();
return this.loginSuccess(result);
this.loginSuccess(result);
return result;
},
logout() {
this.$reset()
this.Session = null;
this.Budgets.clear();
},
}
})