aboutsummaryrefslogtreecommitdiff
path: root/src/components/remote_user_resolver/remote_user_resolver.js
blob: 9b5e511e0390ec60b55749d27f67bb457d61d040 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const RemoteUserResolver = {
  data: () => ({
    error: false
  }),
  mounted () {
    this.redirect()
  },
  methods: {
    redirect () {
      const acct = this.$route.params.username + '@' + this.$route.params.hostname
      this.$store.state.api.backendInteractor.fetchUser({ id: acct })
        .then((externalUser) => {
          if (externalUser.error) {
            this.error = true
          } else {
            this.$store.commit('addNewUsers', [externalUser])
            const id = externalUser.id
            this.$router.replace({
              name: 'external-user-profile',
              params: { id }
            })
          }
        })
        .catch(() => {
          this.error = true
        })
    }
  }
}

export default RemoteUserResolver