mirror of
https://github.com/elk-zone/elk.git
synced 2024-12-05 03:59:59 +03:00
34 lines
690 B
TypeScript
34 lines
690 B
TypeScript
export default defineNuxtRouteMiddleware(async (to) => {
|
|
if (process.server)
|
|
return
|
|
|
|
const masto = useMasto()
|
|
|
|
// Skip running middleware before masto has been initialised
|
|
if (!masto)
|
|
return
|
|
|
|
if (!('server' in to.params))
|
|
return
|
|
|
|
const user = currentUser.value
|
|
|
|
// Handle redirecting to new permalink structure for users with old links
|
|
if (!to.params.server) {
|
|
return {
|
|
...to,
|
|
params: {
|
|
...to.params,
|
|
server: user.server,
|
|
},
|
|
}
|
|
}
|
|
|
|
// No need to additionally resolve an id if we're already logged in
|
|
if (user.server === to.params.server)
|
|
return
|
|
|
|
masto.loginTo({
|
|
server: to.params.server as string,
|
|
})
|
|
})
|