Commit 84afa880 authored by Andres Käver's avatar Andres Käver

state

parent 376555eb
......@@ -5,7 +5,7 @@
<a class="nav-link text-dark" href>user@user.com</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" href>Logout</a>
<a @click="logoutOnClick" class="nav-link text-dark" href>Logout</a>
</li>
</template>
<li v-else class="nav-item">
......@@ -15,9 +15,18 @@
</template>
<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";
import store from '../store';
import router from '../router';
@Component
export default class Identity extends Vue {
private isAuthenticated = false;
get isAuthenticated(): boolean {
return store.getters.isAuthenticated
}
logoutOnClick(): void {
store.dispatch('clearJwt');
router.push('/');
}
}
</script>
......@@ -5,10 +5,22 @@ Vue.use(Vuex)
export default new Vuex.Store({
state: {
jwt: null as string | null
},
mutations: {
setJwt(state, jwt: string | null) {
state.jwt = jwt;
}
},
getters: {
isAuthenticated(context): boolean {
return context.jwt !== null;
}
},
actions: {
clearJwt(context): void {
context.commit('setJwt', null);
}
},
modules: {
}
......
......@@ -5,14 +5,14 @@
<hr />
<div class="form-group">
<label for="Input_Email">Email</label>
<input class="form-control" type="email" id="Input_Email" />
<input v-model="loginInfo.email" class="form-control" type="email" id="Input_Email" />
</div>
<div class="form-group">
<label for="Input_Password">Password</label>
<input class="form-control" type="password" id="Input_Password" />
<input v-model="loginInfo.password" class="form-control" type="password" id="Input_Password" />
</div>
<div class="form-group">
<button class="btn btn-primary">Log in</button>
<button @click="loginOnClick($event)" class="btn btn-primary">Log in</button>
</div>
</div>
</div>
......@@ -21,6 +21,7 @@
<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";
import { ILoginDTO } from "@/types/ILoginDTO";
import store from '../../store';
@Component
export default class GpsLocationTypesIndex extends Vue {
......@@ -29,6 +30,13 @@ export default class GpsLocationTypesIndex extends Vue {
password: "Kala.maja2020"
};
loginOnClick(event: Event): void {
console.log('loginOnClick', event);
console.log('loginInfo', this.loginInfo);
// how to login?
store.commit('setJwt', 'token is here! we are logged-in');
}
// ============ Lifecycle methods ==========
beforeCreate(): void {
console.log("beforeCreate");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment