purityselect/resources/js/plugins/casl/ability.js
2024-10-25 01:05:27 +05:00

17 lines
618 B
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Ability } from '@casl/ability'
export const initialAbility = [
{
action: 'read',
subject: 'Auth',
},
]
// Read ability from localStorage
// 👉 Handles auto fetching previous abilities if already logged in user
// You can update this if you store user abilities to more secure place
// ❗ Anyone can update localStorage so be careful and please update this
const stringifiedUserAbilities = localStorage.getItem('userAbilities')
const existingAbility = stringifiedUserAbilities ? JSON.parse(stringifiedUserAbilities) : null
export default new Ability(existingAbility || initialAbility)