agola-web/src/views/Oauth2.vue

62 lines
1.4 KiB
Vue
Raw Normal View History

2018-12-09 13:21:20 +00:00
<template>
<div>
<div
v-if="error"
class="mb-10 bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative"
role="alert"
>
<span class="block sm:inline">{{ error }}</span>
</div>
2018-12-09 13:21:20 +00:00
</div>
</template>
<script>
import { fetch } from "@/util/data";
import { oauth2callbackurl, setLoggedUser } from "@/util/auth";
2018-12-09 13:21:20 +00:00
export default {
components: {},
name: "Oauth2",
props: {},
data() {
return {
error: null,
2018-12-09 13:21:20 +00:00
run: null,
code: this.$route.query.code,
2019-03-29 17:08:54 +00:00
username: null
2018-12-09 13:21:20 +00:00
};
},
methods: {
2019-03-29 17:08:54 +00:00
async doOauth2() {
2018-12-09 13:21:20 +00:00
let u = oauth2callbackurl();
u.searchParams.append("code", this.$route.query.code);
u.searchParams.append("state", this.$route.query.state);
let { data, error } = await fetch(u);
if (error) {
// set local login error on failed oauth2.
this.error = error;
return;
}
if (data.request_type === "loginuser") {
setLoggedUser(data.response.token, data.response.user);
2019-03-29 17:08:54 +00:00
this.$router.push("/");
} else if (data.request_type === "authorize") {
this.$store.dispatch("setRegisterUser", data.response);
2019-03-29 17:08:54 +00:00
this.$router.push("/register");
} else if (data.request_type === "createuserla") {
this.$router.push({
name: "user settings",
params: { username: this.username }
});
2019-03-29 17:08:54 +00:00
}
2018-12-09 13:21:20 +00:00
}
},
created: function() {
this.doOauth2();
}
};
</script>