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:
@@ -104,7 +104,7 @@ import { CREATE_FEED_TOKEN_ACTOR } from '@/graphql/feed_tokens';
|
||||
query: FETCH_PERSON,
|
||||
variables() {
|
||||
return {
|
||||
name: this.$route.params.name,
|
||||
username: this.$route.params.name,
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -95,7 +95,7 @@ import { MOBILIZON_INSTANCE_HOST } from '@/api/_entrypoint';
|
||||
import { Dialog } from 'buefy/dist/components/dialog';
|
||||
import { RouteName } from '@/router';
|
||||
import { buildFileFromIPicture, buildFileVariable } from '@/utils/image';
|
||||
import { changeIdentity, saveActorData } from '@/utils/auth';
|
||||
import { changeIdentity } from '@/utils/auth';
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
@@ -165,7 +165,9 @@ export default class EditIdentity extends Vue {
|
||||
try {
|
||||
await this.$apollo.mutate({
|
||||
mutation: DELETE_PERSON,
|
||||
variables: this.identity,
|
||||
variables: {
|
||||
id: this.identity.id,
|
||||
},
|
||||
update: (store) => {
|
||||
const data = store.readQuery<{ identities: IPerson[] }>({ query: IDENTITIES });
|
||||
|
||||
@@ -278,11 +280,11 @@ export default class EditIdentity extends Vue {
|
||||
const result = await this.$apollo.query({
|
||||
query: FETCH_PERSON,
|
||||
variables: {
|
||||
name: this.identityName,
|
||||
username: this.identityName,
|
||||
},
|
||||
});
|
||||
|
||||
return new Person(result.data.person);
|
||||
return new Person(result.data.fetchPerson);
|
||||
}
|
||||
|
||||
private handleError(err: any) {
|
||||
|
||||
Reference in New Issue
Block a user