Redirect to profile creation when user has no identities

Also load persons by ID instead of preferred_username

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-10-04 18:28:25 +02:00
parent e34f304b76
commit 471e8ac472
15 changed files with 269 additions and 170 deletions

View File

@@ -69,10 +69,12 @@
<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';
import { IPerson } from '@/types/actor';
import { REGISTER_PERSON } from '@/graphql/actor';
import { IPerson, Person } from '@/types/actor';
import { IDENTITIES, REGISTER_PERSON } from '@/graphql/actor';
import { MOBILIZON_INSTANCE_HOST } from '@/api/_entrypoint';
import { RouteName } from '@/router';
import { changeIdentity } from '@/utils/auth';
import { ICurrentUser } from '@/types/current-user.model';
@Component
export default class Register extends Vue {
@@ -81,19 +83,7 @@ export default class Register extends Vue {
host?: string = MOBILIZON_INSTANCE_HOST;
person: IPerson = {
preferredUsername: '',
name: '',
summary: '',
url: '',
suspended: false,
avatar: null,
banner: null,
domain: null,
feedTokens: [],
goingToEvents: [],
participations: [],
};
person: IPerson = new Person();
errors: object = {};
validationSent: boolean = false;
sendingValidation: boolean = false;
@@ -102,14 +92,26 @@ export default class Register extends Vue {
try {
this.sendingValidation = true;
this.errors = {};
await this.$apollo.mutate({
const { data } = await this.$apollo.mutate<{ registerPerson: IPerson }>({
mutation: REGISTER_PERSON,
variables: Object.assign({ email: this.email }, this.person),
});
this.validationSent = true;
update: (store, { data }) => {
const identitiesData = store.readQuery<{ identities: IPerson[] }>({ query: IDENTITIES });
if (this.userAlreadyActivated) {
this.$router.push({ name: RouteName.HOME });
if (identitiesData && data) {
identitiesData.identities.push(data.registerPerson);
store.writeQuery({ query: IDENTITIES, data: identitiesData });
}
},
});
if (data) {
this.validationSent = true;
if (this.userAlreadyActivated) {
await changeIdentity(this.$apollo.provider.defaultClient, data.registerPerson);
await this.$router.push({ name: RouteName.HOME });
}
}
} catch (error) {
this.errors = error.graphQLErrors.reduce((acc, error) => {