Skip to content

Commit

Permalink
Fix on authToken and get this user route
Browse files Browse the repository at this point in the history
  • Loading branch information
Liam Cabra Teixeira committed Oct 18, 2020
1 parent 5cd3b97 commit 5d6985d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
5 changes: 3 additions & 2 deletions src/components/cpmToolBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

<div>
<v-col align="center" class="mt-10">
<v-btn to="/Login" await @click="logOff()" color="red" dark>SAIR</v-btn>
<v-btn @click="logOff" color="red" dark>SAIR</v-btn>
</v-col>
</div>

Expand All @@ -85,7 +85,8 @@
}),
methods: {
async logOff(){
localStorage.removeItem('token')
await localStorage.removeItem('token');
await localStorage.removeItem('id');
await this.$router.push('/')
}
Expand Down
6 changes: 3 additions & 3 deletions src/store/modules/LoginVuex.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export default {

},

async authToken (context, newData) {
async authToken (context) {

const autho = await axios.post(process.env.VUE_APP_BASE_URL + '/user/authToken', newData + 'a')
const autho = await axios.post(process.env.VUE_APP_BASE_URL + '/user/authToken')

return autho
return autho.data;

},

Expand Down
8 changes: 2 additions & 6 deletions src/store/modules/ProfileVuex.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ export default {

actions: {
async getUser(context){
const token = localStorage.getItem('token');
const decodedToken = await axios.post(process.env.VUE_APP_BASE_URL+'/user/authToken', token);

console.log(decodedToken)

const user = await axios.get(process.env.VUE_APP_BASE_URL+`/user/mail/${decodedToken.data}`);

const user = await axios.get(process.env.VUE_APP_BASE_URL+`/user/this`);
return user.data;
},

Expand Down
9 changes: 7 additions & 2 deletions src/views/private/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</v-row>
</div>

<div class="mb-6" v-else v-for="event in events" :key="event.id">
<div class="mb-6 p10" v-else v-for="event in events" :key="event.id">
<EventCard class="mt-4 card" :cardData="event" />
</div>

Expand All @@ -58,7 +58,7 @@
</div>
</v-card>
<v-col class="text-center mt-7" cols="1" sm="12">
<v-btn align="center" class="ml-2" color="red" dark>SAIR</v-btn>
<v-btn align="center" class="ml-2" color="red" @click="logOut()" dark>SAIR</v-btn>
</v-col>
</v-card>
</div>
Expand Down Expand Up @@ -105,7 +105,12 @@ export default {
getMyEvents: "ProfileVuex/getMyEvents",
updateAvatar: "ProfileVuex/updateAvatar",
}),
logOut(){
localStorage.removeItem('token');
localStorage.removeItem('id');
this.$router.push('/Home');
},
async loadUser() {
const user = await this.getUser();
Expand Down
9 changes: 5 additions & 4 deletions src/views/public/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ export default {
created() {
if (localStorage.token) {
this.checkToken().then(() => this.$router.push('/Feed'))
this.checkToken();
}
},
Expand Down Expand Up @@ -84,15 +83,17 @@ export default {
async checkToken() {
const isAuth = await this.authToken(localStorage.token)
const isAuth = await this.authToken();
if (isAuth) {
if (isAuth != false) {
this.$toast.success('Logado!', 'Hey', {
position: "topCenter"
})
this.$router.push('/Feed')
}
console.log(isAuth)
}
}
}
Expand Down

0 comments on commit 5d6985d

Please sign in to comment.