You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api.md
+92-11Lines changed: 92 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,31 +68,112 @@ This function is currently not supported.
68
68
69
69
This function is currently not supported.
70
70
71
-
### authorizer(rules) ⇒ this
71
+
### authorizer(config) ⇒ this
72
72
73
-
Configure authorization rules. The `rules` object is a map from table name to
74
-
`Authorization` object, which defines if access to table is allowed or denied.
75
-
If a table has no authorization rule, access to it is _denied_ by default.
73
+
Configure authorization rules for the database. Accepts three formats:
76
74
77
-
Example:
75
+
-**Legacy format** — a map from table name to `Authorization.ALLOW` or `Authorization.DENY`
76
+
-**Rule-based format** — an `AuthorizerConfig` object with ordered rules and pattern matching
77
+
-**`null`** — removes the authorizer entirely
78
+
79
+
#### Legacy format
80
+
81
+
A simple object mapping table names to `Authorization.ALLOW` (0) or `Authorization.DENY` (1).
82
+
Tables without an entry are denied by default.
78
83
79
84
```javascript
85
+
const { Authorization } =require('libsql');
86
+
80
87
db.authorizer({
81
-
"users":Authorization.ALLOW
88
+
"users":Authorization.ALLOW,
89
+
"secrets":Authorization.DENY,
82
90
});
83
91
84
-
// Access is allowed.
92
+
// Access to "users" is allowed.
85
93
conststmt=db.prepare("SELECT * FROM users");
86
94
95
+
// Access to "secrets" throws SQLITE_AUTH.
96
+
conststmt=db.prepare("SELECT * FROM secrets"); // Error!
97
+
```
98
+
99
+
#### Rule-based format
100
+
101
+
An object with a `rules` array and an optional `defaultPolicy`. Rules are evaluated in order — **first match wins**. If no rule matches, `defaultPolicy` applies (defaults to `DENY`).
0 commit comments