diff --git a/js/src/graphql/user.ts b/js/src/graphql/user.ts
index 0db4b548..07a16aba 100644
--- a/js/src/graphql/user.ts
+++ b/js/src/graphql/user.ts
@@ -15,6 +15,10 @@ mutation ValidateUser($token: String!) {
token,
user {
id,
+ email,
+ defaultActor {
+ id
+ }
}
}
}
@@ -33,4 +37,4 @@ export const UPDATE_CURRENT_USER_CLIENT = gql`
mutation UpdateCurrentUser($id: Int!, $email: String!) {
updateCurrentUser(id: $id, email: $email) @client
}
-`
+`;
diff --git a/js/src/router/user.ts b/js/src/router/user.ts
index bdec6752..81172373 100644
--- a/js/src/router/user.ts
+++ b/js/src/router/user.ts
@@ -46,7 +46,8 @@ export default [
path: '/validate/:token',
name: 'Validate',
component: Validate,
- props: true,
+ // We can only pass string values through params, therefore
+ props: (route) => ({ email: route.params.email, userAlreadyActivated: route.params.userAlreadyActivated === 'true'}),
meta: { requiresAuth: false },
},
{
diff --git a/js/src/views/Account/Register.vue b/js/src/views/Account/Register.vue
index a644049f..0e9b2a72 100644
--- a/js/src/views/Account/Register.vue
+++ b/js/src/views/Account/Register.vue
@@ -57,7 +57,7 @@
-
+
{
acc[error.details] = error.message;
diff --git a/js/src/views/User/Validate.vue b/js/src/views/User/Validate.vue
index 801a13a9..9187aed1 100644
--- a/js/src/views/User/Validate.vue
+++ b/js/src/views/User/Validate.vue
@@ -5,8 +5,8 @@
-
- Error while validating account
+
+ Either the account is already validated, either the validation token is incorrect.
@@ -28,21 +28,28 @@ export default class Validate extends Vue {
loading = true;
failed = false;
- created() {
- this.validateAction();
+ async created() {
+ await this.validateAction();
}
async validateAction() {
try {
- const data = await this.$apollo.mutate({
+ const { data } = await this.$apollo.mutate({
mutation: VALIDATE_USER,
variables: {
token: this.token
}
});
- this.saveUserData(data.data);
- this.$router.push({ name: "Home" });
+ this.saveUserData(data);
+
+ const user = data.validateUser.user;
+ console.log(user);
+ if (user.defaultActor) {
+ this.$router.push({name: "Home"});
+ } else { // If the user didn't register any profile yet, let's create one for them
+ this.$router.push({ name: 'RegisterProfile', params: {email: user.email, userAlreadyActivated: 'true'} });
+ }
} catch (err) {
console.error(err);
this.failed = true;
diff --git a/lib/mobilizon_web/resolvers/person.ex b/lib/mobilizon_web/resolvers/person.ex
index 2258d49d..8a3d4ba7 100644
--- a/lib/mobilizon_web/resolvers/person.ex
+++ b/lib/mobilizon_web/resolvers/person.ex
@@ -77,8 +77,12 @@ defmodule MobilizonWeb.Resolvers.Person do
else
{:error, :user_not_found} ->
{:error, "User with email not found"}
+
{:no_actor, _} ->
{:error, "You already have a profile for this user"}
+
+ {:error, %Ecto.Changeset{} = e} ->
+ {:error, e}
end
end
end
diff --git a/lib/mobilizon_web/resolvers/user.ex b/lib/mobilizon_web/resolvers/user.ex
index f8d45fbb..12594c6a 100644
--- a/lib/mobilizon_web/resolvers/user.ex
+++ b/lib/mobilizon_web/resolvers/user.ex
@@ -63,7 +63,7 @@ defmodule MobilizonWeb.Resolvers.User do
{:get_actor, actor} <- {:get_actor, Actors.get_actor_for_user(user)},
{:guardian_encode_and_sign, {:ok, token, _}} <-
{:guardian_encode_and_sign, MobilizonWeb.Guardian.encode_and_sign(user)} do
- {:ok, %{token: token, user: user, person: actor}}
+ {:ok, %{token: token, user: Map.put(user, :default_actor, actor)}}
else
err ->
Logger.info("Unable to validate user with token #{token}")