-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add authentication, permission and role directives
- Loading branch information
1 parent
087ad02
commit 198bd12
Showing
12 changed files
with
123 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useConfigurationStore } from '@/stores/configurationStore'; | ||
import { storeToRefs } from 'pinia'; | ||
import { type Directive, watch } from 'vue'; | ||
|
||
const authenticated: Directive<HTMLElement, null> = (el) => { | ||
const configurationStore = useConfigurationStore(); | ||
const { isAuthenticated } = storeToRefs(configurationStore); | ||
|
||
const checkAuthentication = () => { | ||
el.hidden = !isAuthenticated.value; | ||
}; | ||
|
||
checkAuthentication(); | ||
|
||
watch(isAuthenticated, (oldValue, newValue) => { | ||
if (oldValue != newValue) checkAuthentication(); | ||
}); | ||
}; | ||
|
||
export { authenticated }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useStructureStore } from '@/stores/structureStore'; | ||
import { storeToRefs } from 'pinia'; | ||
import { type Directive, watch } from 'vue'; | ||
|
||
const permission: Directive<HTMLElement, Array<string>> = (el, binding) => { | ||
const structureStore = useStructureStore(); | ||
const { currentEtab } = storeToRefs(structureStore); | ||
|
||
const checkPermissions = () => { | ||
let hasPermission: boolean = false; | ||
binding.value.forEach((permission) => { | ||
if (currentEtab.value?.permission?.includes(permission)) hasPermission = true; | ||
}); | ||
|
||
el.hidden = !hasPermission; | ||
}; | ||
|
||
checkPermissions(); | ||
|
||
watch( | ||
() => currentEtab.value?.permission, | ||
(oldValue, newValue) => { | ||
if (newValue != oldValue) checkPermissions(); | ||
}, | ||
); | ||
}; | ||
|
||
export { permission }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useConfigurationStore } from '@/stores/configurationStore'; | ||
import { storeToRefs } from 'pinia'; | ||
import { type Directive, watch } from 'vue'; | ||
|
||
const admin: Directive<HTMLElement, null> = (el) => { | ||
const configurationStore = useConfigurationStore(); | ||
const { identity } = storeToRefs(configurationStore); | ||
|
||
const checkAdmin = () => { | ||
let isAdmin: boolean = false; | ||
if (identity.value?.roles.includes('ROLE_ADMIN')) isAdmin = true; | ||
|
||
el.hidden = !isAdmin; | ||
}; | ||
|
||
checkAdmin(); | ||
|
||
watch( | ||
() => identity.value?.roles, | ||
() => checkAdmin(), | ||
{ deep: true }, | ||
); | ||
}; | ||
|
||
const role: Directive<HTMLElement, Array<string>> = (el, binding) => { | ||
const configurationStore = useConfigurationStore(); | ||
const { identity } = storeToRefs(configurationStore); | ||
|
||
const checkRoles = () => { | ||
let hasRole: boolean = false; | ||
binding.value.forEach((role) => { | ||
if (identity.value?.roles.includes(role)) hasRole = true; | ||
}); | ||
|
||
el.hidden = !hasRole; | ||
}; | ||
|
||
checkRoles(); | ||
|
||
watch( | ||
() => identity.value?.roles, | ||
() => checkRoles(), | ||
{ deep: true }, | ||
); | ||
}; | ||
|
||
export { admin, role }; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters