redirect /remote-users/:username@:hostname -> /users/:id, /remote-users/:hostname/:username -> /users/:id

This commit is contained in:
Hakaba Hitoyo 2019-11-08 22:27:25 +00:00 committed by HJ
parent 2b68134ab0
commit e4820012a3
4 changed files with 67 additions and 0 deletions

View file

@ -0,0 +1,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