Skip to content

Commit 704b072

Browse files
committed
Register $checkAccess globally
1 parent 521bd8c commit 704b072

File tree

9 files changed

+57
-15
lines changed

9 files changed

+57
-15
lines changed

packages/skeleton/env.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/// <reference types="vite/client" />
22
/// <reference types="@userfrosting/sprinkle-core" />
3+
/// <reference types="@userfrosting/sprinkle-account" />
34
/// <reference types="@userfrosting/theme-pink-cupcake/components" />
5+
46
/**
57
* This is required for webpack to correctly import vue file when using TypeScript.
68
*/
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export {}
2+
3+
declare module 'vue' {
4+
interface ComponentCustomProperties {
5+
$checkAccess: (slug: string) => Boolean
6+
}
7+
}

packages/sprinkle-account/app/assets/index.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,29 @@ import type { Router } from 'vue-router'
33
import { useAuthStore } from './stores/auth'
44
import { useAuthGuard } from './guards/authGuard'
55

6-
/* Install plugins */
6+
/**
7+
* Account Sprinkle initialization recipe.
8+
*
9+
* This recipe is responsible for running the auth check on load, setting up
10+
* the router guards and registering the checkAccess as a global properties.
11+
*/
712
export default {
813
install: (app: App, options: { router: Router }) => {
9-
// Run auth check on load
14+
/**
15+
* Run auth check on load
16+
*/
1017
const auth = useAuthStore()
1118
auth.check()
1219

13-
// Setup router guards
20+
/**
21+
* Setup router guards
22+
*/
1423
const { router } = options
1524
useAuthGuard(router)
25+
26+
/**
27+
* Register checkAccess as a global property
28+
*/
29+
app.config.globalProperties.$checkAccess = auth.checkAccess
1630
}
1731
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
/* Install plugins */
1+
/**
2+
* Admin Sprinkle initialization recipe.
3+
*/
24
export default {
35
install: () => {}
46
}

packages/sprinkle-admin/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="vite/client" />
22
/// <reference types="@userfrosting/sprinkle-core" />
3+
/// <reference types="@userfrosting/sprinkle-account" />
34

45
import { createPinia } from 'pinia'
56
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'

packages/sprinkle-core/app/assets/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export {}
22

33
declare module 'vue' {
44
interface ComponentCustomProperties {
5-
// TODO : Use interface from sprinkle-core
65
$t: (key: string, placeholders?: string | number | object) => string
76
$tdate: (date: string, format?: string | object) => string
87
}

packages/sprinkle-core/app/assets/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@ import { useConfigStore, useTranslator } from './stores'
44
/**
55
* Core Sprinkle initialization recipe.
66
*
7-
* This recipe is responsible for loading the configuration from the api.
7+
* This recipe is responsible for loading the configuration from the api,
8+
* loading the translations and register the translator as $t and $tdate global
9+
* properties.
810
*/
911
export default {
1012
install: (app: App) => {
13+
/**
14+
* Load configuration
15+
*/
1116
useConfigStore().load()
1217

13-
// Load translations & add $t to global properties
14-
const { translate, translateDate, load } = useTranslator()
15-
load()
16-
app.config.globalProperties.$t = translate
17-
app.config.globalProperties.$tdate = translateDate
18+
/**
19+
* Load translations & add $t+$tdate to global properties
20+
*/
21+
const translator = useTranslator()
22+
translator.load()
23+
app.config.globalProperties.$t = translator.translate
24+
app.config.globalProperties.$tdate = translator.translateDate
1825
}
1926
}

packages/theme-pink-cupcake/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="vite/client" />
22
/// <reference types="@userfrosting/sprinkle-core" />
3+
/// <reference types="@userfrosting/sprinkle-account" />
34

45
import { createPinia } from 'pinia'
56
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
import type { App } from 'vue'
22

3-
// Import sub-plugins
3+
/**
4+
* Import sub-plugins.
5+
*/
46
import PinkCupcakeComponents from './plugins/components'
57
import AdminSprinkle from './plugins/admin'
68
import AccountSprinkle from './plugins/account'
79
import CoreSprinkle from './plugins/core'
810
import FontAwesome from './plugins/font-awesome'
911

10-
// Init UIkit
12+
/**
13+
* Import UIkit and its icons.
14+
*/
1115
import UIkit from 'uikit'
1216
import Icons from 'uikit/dist/js/uikit-icons'
1317
UIkit.use(Icons)
1418

15-
/* Install plugins */
19+
/**
20+
* Pink Cupcake Theme initialization recipe.
21+
*
22+
* This recipe is responsible for loading the Pink Cupcake, Admin, Account and
23+
* Core sprinkle plugins. It also load the FontAwesome icons.
24+
*/
1625
export default {
1726
install: (app: App) => {
1827
app.use(PinkCupcakeComponents)
1928
app.use(AdminSprinkle) // TODO : Add option to disable this or load on demand
2029
app.use(AccountSprinkle) // TODO : Add option to disable this or load on demand
21-
app.use(CoreSprinkle)
30+
app.use(CoreSprinkle)
2231
app.use(FontAwesome)
2332
}
2433
}

0 commit comments

Comments
 (0)