Skip to content

Commit c1e56de

Browse files
committed
Switch to initMetadata
1 parent f376d69 commit c1e56de

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

MyApp.Client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"dependencies": {
1212
"@servicestack/client": "^2.1.13",
13-
"@servicestack/vue": "^3.1.3",
13+
"@servicestack/vue": "^3.1.4",
1414
"@tailwindcss/forms": "^0.5.10",
1515
"@tailwindcss/vite": "^4.1.17",
1616
"tailwindcss": "^4.1.17",

MyApp.Client/src/lib/auth.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ const { user, hasRole, hasPermission, signIn, signOut } = useAuth()
3131

3232
export { user, hasRole, hasPermission }
3333

34-
checkAuth().then(auth => {
35-
if (auth) signIn(auth)
36-
else signOut()
37-
})
38-
3934
export async function revalidate() {
4035
loading.value = true
4136
const auth = await checkAuth()
@@ -55,7 +50,6 @@ export const signout = async (router:any, redirectTo?: string) => {
5550
await router.replace({ path: redirectTo ?? router?.currentRoute?.value.path, force: true })
5651
}
5752

58-
// Use Route Guards to guard against access to pages
5953
export function configRouter(router:Router) {
6054
const invalidAttrRedirect = (to:RouteLocationNormalized, _:string, userAttrs:string[]) => userAttrs.indexOf('auth') === -1
6155
? Routes.signin(to.path)
@@ -73,7 +67,7 @@ export function configRouter(router:Router) {
7367
const allowAdmin = isAdmin && (attr.startsWith('role:') || attr.startsWith('perm:'))
7468
if (!allowAdmin) {
7569
const goTo = invalidAttrRedirect(to, attr, attrs)
76-
console.log(`Redirecting to ${goTo} as missing required '${attr}' to access '${to.path}'`)
70+
console.debug(`Redirecting to ${goTo} as missing required '${attr}' to access '${to.path}'`)
7771
next(goTo)
7872
return
7973
}

MyApp.Client/src/lib/gateway.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { JsonServiceClient } from "@servicestack/client"
2-
import { useMetadata } from "@servicestack/vue"
2+
import { useAuth, initMetadata } from "@servicestack/vue"
33
import type { Router } from "vue-router"
44
import { checkAuth } from "./auth"
55

@@ -30,16 +30,17 @@ export const Routes = {
3030
forbidden: () => '/forbidden',
3131
guards: [
3232
Requires.auth('/profile'),
33-
] as RouteGuard[],
33+
],
3434
}
3535

3636
export const client = new JsonServiceClient()
3737

3838
export function useApp() {
3939
async function load() {
40-
const { loadMetadata } = useMetadata()
41-
loadMetadata({ client, olderThan:0 })
42-
await checkAuth()
40+
const { signIn } = useAuth()
41+
initMetadata({ client })
42+
const auth = await checkAuth()
43+
if (auth) signIn(auth)
4344
}
4445
return {
4546
load,

0 commit comments

Comments
 (0)