2021-08-09 19:29:15 +02:00
|
|
|
<template>
|
|
|
|
<p>{{ $t("Redirecting in progress…") }}</p>
|
|
|
|
</template>
|
2020-06-27 19:12:45 +02:00
|
|
|
<script lang="ts">
|
2020-11-27 19:27:44 +01:00
|
|
|
import { Component, Vue } from "vue-property-decorator";
|
|
|
|
import { ICurrentUserRole } from "@/types/enums";
|
|
|
|
import { UPDATE_CURRENT_USER_CLIENT, LOGGED_USER } from "../../graphql/user";
|
2020-06-27 19:12:45 +02:00
|
|
|
import RouteName from "../../router/name";
|
|
|
|
import { saveUserData, changeIdentity } from "../../utils/auth";
|
2020-11-27 19:27:44 +01:00
|
|
|
import { IUser } from "../../types/current-user.model";
|
2020-06-27 19:12:45 +02:00
|
|
|
|
2021-10-10 16:24:12 +02:00
|
|
|
@Component({
|
|
|
|
metaInfo() {
|
|
|
|
return {
|
|
|
|
title: this.$t("Redirecting to Mobilizon") as string,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
})
|
2020-06-27 19:12:45 +02:00
|
|
|
export default class ProviderValidate extends Vue {
|
2020-11-27 19:27:44 +01:00
|
|
|
async mounted(): Promise<void> {
|
2020-06-27 19:12:45 +02:00
|
|
|
const accessToken = this.getValueFromMeta("auth-access-token");
|
|
|
|
const refreshToken = this.getValueFromMeta("auth-refresh-token");
|
|
|
|
const userId = this.getValueFromMeta("auth-user-id");
|
|
|
|
const userEmail = this.getValueFromMeta("auth-user-email");
|
2020-11-30 10:24:11 +01:00
|
|
|
const userRole = this.getValueFromMeta(
|
|
|
|
"auth-user-role"
|
|
|
|
) as ICurrentUserRole;
|
2020-06-27 19:12:45 +02:00
|
|
|
|
|
|
|
if (!(userId && userEmail && userRole && accessToken && refreshToken)) {
|
2020-11-27 19:27:44 +01:00
|
|
|
await this.$router.push("/");
|
2020-06-27 19:12:45 +02:00
|
|
|
} else {
|
2020-11-27 19:27:44 +01:00
|
|
|
const login = {
|
2020-11-30 10:24:11 +01:00
|
|
|
user: {
|
|
|
|
id: userId,
|
|
|
|
email: userEmail,
|
|
|
|
role: userRole,
|
|
|
|
isLoggedIn: true,
|
|
|
|
},
|
2020-11-27 19:27:44 +01:00
|
|
|
accessToken,
|
|
|
|
refreshToken,
|
|
|
|
};
|
|
|
|
saveUserData(login);
|
|
|
|
await this.$apollo.mutate({
|
|
|
|
mutation: UPDATE_CURRENT_USER_CLIENT,
|
|
|
|
variables: {
|
|
|
|
id: userId,
|
|
|
|
email: userEmail,
|
|
|
|
isLoggedIn: true,
|
|
|
|
role: ICurrentUserRole.USER,
|
|
|
|
},
|
2020-06-27 19:12:45 +02:00
|
|
|
});
|
2020-11-27 19:27:44 +01:00
|
|
|
const { data } = await this.$apollo.query<{ loggedUser: IUser }>({
|
|
|
|
query: LOGGED_USER,
|
|
|
|
});
|
|
|
|
const { loggedUser } = data;
|
|
|
|
|
|
|
|
if (loggedUser.defaultActor) {
|
2020-11-30 10:24:11 +01:00
|
|
|
await changeIdentity(
|
|
|
|
this.$apollo.provider.defaultClient,
|
|
|
|
loggedUser.defaultActor
|
|
|
|
);
|
2020-11-27 19:27:44 +01:00
|
|
|
await this.$router.push({ name: RouteName.HOME });
|
|
|
|
} else {
|
2021-08-09 19:29:15 +02:00
|
|
|
// No need to push to REGISTER_PROFILE, the navbar will do it for us
|
2020-11-27 19:27:44 +01:00
|
|
|
}
|
2020-06-27 19:12:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 19:27:44 +01:00
|
|
|
// eslint-disable-next-line class-methods-use-this
|
|
|
|
getValueFromMeta(name: string): string | null {
|
2020-06-27 19:12:45 +02:00
|
|
|
const element = document.querySelector(`meta[name="${name}"]`);
|
|
|
|
if (element && element.getAttribute("content")) {
|
|
|
|
return element.getAttribute("content");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|