mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-19 07:19:58 +00:00
refactor: move post-login push logic to single place
This commit is contained in:
parent
d9e8703882
commit
72855d7725
2 changed files with 9 additions and 10 deletions
|
@ -88,7 +88,12 @@ async function loginTo(user?: Omit<UserLogin, 'account'> & { account?: AccountCr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('server' in route.params && user?.token && !useNuxtApp()._processingMiddleware) {
|
// This only cleans up the URL; page content should stay the same
|
||||||
|
if (route.path === '/signin/callback') {
|
||||||
|
await router.push('/home')
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ('server' in route.params && user?.token && !useNuxtApp()._processingMiddleware) {
|
||||||
await router.push({
|
await router.push({
|
||||||
...route,
|
...route,
|
||||||
force: true,
|
force: true,
|
||||||
|
|
|
@ -2,8 +2,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
||||||
const masto = createMasto()
|
const masto = createMasto()
|
||||||
|
|
||||||
if (process.client) {
|
if (process.client) {
|
||||||
const { query, path } = useRoute()
|
const { query } = useRoute()
|
||||||
const router = useRouter()
|
|
||||||
const user = typeof query.server === 'string' && typeof query.token === 'string'
|
const user = typeof query.server === 'string' && typeof query.token === 'string'
|
||||||
? {
|
? {
|
||||||
server: query.server,
|
server: query.server,
|
||||||
|
@ -14,13 +13,8 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
||||||
|
|
||||||
nuxtApp.hook('app:suspense:resolve', () => {
|
nuxtApp.hook('app:suspense:resolve', () => {
|
||||||
// TODO: improve upstream to make this synchronous (delayed auth)
|
// TODO: improve upstream to make this synchronous (delayed auth)
|
||||||
if (!masto.loggedIn.value) {
|
if (!masto.loggedIn.value)
|
||||||
masto.loginTo(user).then(() => {
|
masto.loginTo(user)
|
||||||
// This only cleans up the URL; page content should stay the same
|
|
||||||
if (path === '/signin/callback')
|
|
||||||
router.push('/home')
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue