Browse Source

🔑 Fix login issues

main
Haris Razis 4 years ago
parent
commit
86aa12df95
  1. 3
      server/routes/auth.js
  2. 29
      web/src/components/Hero.vue
  3. 7
      web/src/store/index.ts
  4. 3
      web/src/views/Login.vue

3
server/routes/auth.js

@ -23,6 +23,9 @@ router.post('/auth/logout', (req, res) => {
}); });
router.get('/auth/current_user', (req, res) => { router.get('/auth/current_user', (req, res) => {
if (!req.user)
return res.status(404).json({errors: 'No current user!'})
res.send(req.user); res.send(req.user);
}); });

29
web/src/components/Hero.vue

@ -1,29 +0,0 @@
<template>
<section class="hero is-primary is-bold">
<div class="hero-body">
<div class="container">
<h3 class="is-size-3">
<span class="icon">
<i class="fas fa-stream"></i>
</span>
<span>&nbsp&nbspWelcome {{ username }},</span>
</h3>
<h2 class="subtitle mt-3">
</h2>
</div>
</div>
</section>
</template>
<script lang="ts">
import {Vue} from 'vue-class-component';
export default class Hero extends Vue {
private username = '';
mounted() {
this.username = this.$store.getters.user.username
}
}
</script>

7
web/src/store/index.ts

@ -63,11 +63,6 @@ export default createStore({
url: '/auth/current_user' url: '/auth/current_user'
}) })
.then((resp: AxiosResponse) => { .then((resp: AxiosResponse) => {
if (resp.data === "") {
commit('auth_error')
return
}
commit("auth_success", resp.data); commit("auth_success", resp.data);
resolve(resp) resolve(resp)
}) })
@ -81,7 +76,7 @@ export default createStore({
modules: {}, modules: {},
getters: { getters: {
isLoggedIn: state => state.status, isLoggedIn: state => state.status,
user: state => state.user user: state => state.user,
}, },
plugins: [createPersistedState()] plugins: [createPersistedState()]
}) })

3
web/src/views/Login.vue

@ -63,7 +63,7 @@ export default class Login extends Vue {
this.$store.dispatch('getCurrentUser') this.$store.dispatch('getCurrentUser')
.then(() => this.$router.push('/dashboard')) .then(() => this.$router.push('/dashboard'))
.catch((err: any) => { .catch((err: any) => {
this.$router.push('/') this.$router.push('/login')
}) })
} }
@ -73,7 +73,6 @@ export default class Login extends Vue {
this.$store.dispatch('login', user) this.$store.dispatch('login', user)
.then(() => this.$router.push('/dashboard')) .then(() => this.$router.push('/dashboard'))
.catch((err: any) => { .catch((err: any) => {
console.log(err)
this.msg = err.response.data.errors.message || err.message || 'Something went wrong!' this.msg = err.response.data.errors.message || err.message || 'Something went wrong!'
this.$router.push('/login') this.$router.push('/login')
}) })

Loading…
Cancel
Save