astro-tokenkit 1.0.23 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/client/tk-client.js +2 -2
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/integration.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -182,6 +182,25 @@ tokenKit({
|
|
|
182
182
|
</script>
|
|
183
183
|
```
|
|
184
184
|
|
|
185
|
+
#### Overriding Auto-Logout Behavior
|
|
186
|
+
|
|
187
|
+
By default, TokenKit automatically calls your logout endpoint and reloads the page. You can override this behavior by providing an `onIdle` callback (function or string) in your configuration.
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
// astro.config.mjs
|
|
191
|
+
export default defineConfig({
|
|
192
|
+
integrations: [
|
|
193
|
+
tokenKit({
|
|
194
|
+
idle: {
|
|
195
|
+
timeout: 60 * 15,
|
|
196
|
+
// Disables default logout/reload and runs this instead
|
|
197
|
+
onIdle: 'myCustomLogout'
|
|
198
|
+
}
|
|
199
|
+
})
|
|
200
|
+
]
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
185
204
|
### Login Options
|
|
186
205
|
|
|
187
206
|
| Property | Type | Description |
|
package/dist/client/tk-client.js
CHANGED
|
@@ -6,13 +6,13 @@ if (typeof window !== 'undefined') {
|
|
|
6
6
|
new IdleManager(Object.assign(Object.assign({}, config.idle), { onIdle: config.idle.onIdle || (() => {
|
|
7
7
|
var _a;
|
|
8
8
|
// Default implementation: auto logout and reload
|
|
9
|
-
// Note: IdleManager dispatches 'tk:idle' automatically
|
|
10
9
|
if (config.idle.autoLogout !== false && ((_a = config.auth) === null || _a === void 0 ? void 0 : _a.logout)) {
|
|
11
10
|
const logoutURL = config.auth.logout.startsWith('http')
|
|
12
11
|
? config.auth.logout
|
|
13
12
|
: (config.baseURL || '') + config.auth.logout;
|
|
14
13
|
fetch(logoutURL, {
|
|
15
|
-
method: 'POST'
|
|
14
|
+
method: 'POST',
|
|
15
|
+
credentials: 'include'
|
|
16
16
|
}).finally(() => {
|
|
17
17
|
if (config.idle.reload !== false) {
|
|
18
18
|
window.location.reload();
|
package/dist/index.cjs
CHANGED
|
@@ -1392,7 +1392,11 @@ function createClient(config) {
|
|
|
1392
1392
|
* ```
|
|
1393
1393
|
*/
|
|
1394
1394
|
function tokenKit(config) {
|
|
1395
|
+
var _a;
|
|
1395
1396
|
setConfig(config);
|
|
1397
|
+
if (((_a = config.idle) === null || _a === void 0 ? void 0 : _a.onIdle) && typeof config.idle.onIdle === 'function') {
|
|
1398
|
+
logger.warn('[TokenKit] Passing a function to "idle.onIdle" in astro.config.mjs is not supported because it is not serializable. Use a string name of a global function or window.addEventListener("tk:idle", ...) instead.');
|
|
1399
|
+
}
|
|
1396
1400
|
// Create a serializable version of the config for the runtime
|
|
1397
1401
|
const serializableConfig = JSON.parse(JSON.stringify(config, (key, value) => {
|
|
1398
1402
|
if (typeof value === 'function')
|