diff --git a/docs/en/UI/AspNetCore/JavaScript-API/Auth.md b/docs/en/UI/AspNetCore/JavaScript-API/Auth.md new file mode 100644 index 0000000000..45af8c4b3e --- /dev/null +++ b/docs/en/UI/AspNetCore/JavaScript-API/Auth.md @@ -0,0 +1,24 @@ +# ASP.NET Core MVC / Razor Pages UI: JavaScript Auth API + +Auth API allows you to check permissions (policies) for the current user in the client side. In this way, you can conditionally show/hide UI parts or perform your client side logic based on the current permissions. + +> This document only explains the JavaScript API. See the [authorization document](../../../Authorization.md) to understand the ABP authorization & permission system. + +## Basic Usage + +`abp.auth.isGranted(...)` function is used to check if a permission/policy has granted or not: + +````js +if (abp.auth.isGranted('DeleteUsers')) { + //TODO: Delete the user +} else { + alert("You don't have permission to delete a user!"); +} +```` + +## Other Fields & Functions + +* ` abp.auth.isAnyGranted(...)`: Gets one or more permission/policy names and returns `true` if at least one of them has granted. +* `abp.auth.areAllGranted(...)`: Gets one or more permission/policy names and returns `true` if all of them of them have granted. +* `abp.auth.policies`: This is an object where its keys are the permission/policy names. You can find all permission/policy names here. +* `abp.auth.grantedPolicies`: This is an object where its keys are the permission/policy names. You can find the granted permission/policy names here. \ No newline at end of file diff --git a/docs/en/UI/AspNetCore/JavaScript-API/Index.md b/docs/en/UI/AspNetCore/JavaScript-API/Index.md index dc87739641..38cde6217e 100644 --- a/docs/en/UI/AspNetCore/JavaScript-API/Index.md +++ b/docs/en/UI/AspNetCore/JavaScript-API/Index.md @@ -5,7 +5,7 @@ ABP provides a set of JavaScript APIs for ASP.NET Core MVC / Razor Pages applica ## APIs * [abp.ajax](Ajax.md) -* abp.auth +* [abp.auth](Auth.md) * abp.currentUser * abp.dom * [abp.event](Events.md) diff --git a/docs/en/docs-nav.json b/docs/en/docs-nav.json index c14349b4ac..1ef289851d 100644 --- a/docs/en/docs-nav.json +++ b/docs/en/docs-nav.json @@ -455,6 +455,10 @@ "text": "Localization", "path": "UI/AspNetCore/JavaScript-API/Localization.md" }, + { + "text": "Auth", + "path": "UI/AspNetCore/JavaScript-API/Auth.md" + }, { "text": "Settings", "path": "UI/AspNetCore/JavaScript-API/Settings.md"