progress if user authenticated

This commit is contained in:
leejinseok
2020-02-06 15:27:56 +09:00
parent c4a0ce9992
commit ed82988a78
4 changed files with 18 additions and 23 deletions

View File

@@ -9,19 +9,16 @@
<script>
import authApi from "../api/authApi";
import authService from "../services/authService";
export default {
name: "Welcome",
async beforeCreate() {
authApi.session = authApi.session.bind(this);
authService.progressIfUserAuthenticated = authService.progressIfUserAuthenticated.bind(this);
},
async created() {
try {
await authApi.session();
await this.$router.replace("/articles");
} catch (e) {
console.log(e);
}
await authService.progressIfUserAuthenticated();
}
};
</script>

View File

@@ -15,23 +15,20 @@
export default {
name: "Login",
beforeCreate() {
authApi.session = authApi.session.bind(this);
authService.login = authService.login.bind(this);
authService.progressIfUserAuthenticated = authService.progressIfUserAuthenticated.bind(this);
},
data() {
return {
email: "",
password: ""
};
},
beforeCreate() {
authApi.session = authApi.session.bind(this);
authService.login = authService.login.bind(this);
},
async created() {
try {
await authApi.session();
await this.$router.replace("/articles");
} catch (e) {
console.log(e);
}
await authService.progressIfUserAuthenticated()
},
methods: {
submit: async function (evt) {

View File

@@ -27,14 +27,10 @@
authApi.session = authApi.session.bind(this);
authService.register = authService.register.bind(this);
authService.progressIfUserAuthenticated = authService.progressIfUserAuthenticated.bind(this);
},
async created() {
try {
await authApi.session();
await this.$router.replace("/articles");
} catch (err) {
console.log(err);
}
await authService.progressIfUserAuthenticated();
},
methods: {
register: async function (evt) {

View File

@@ -35,7 +35,12 @@ export default {
}
},
async progressIfUserAuthenticated() {
try {
await authApi.session(commonUtil.getAuthenticationHeaderBearer(this.$cookie.get('accessToken')));
await this.$router.replace('/articles');
} catch (err) {
console.log(err);
}
},
async banishIfUserUnAuthenticated() {
try {