extended JS and TS template with Bearer token
This commit is contained in:
@ -238,11 +238,15 @@ You can also download generated frontend clients:
|
||||
* JavaScript: `?format=javascript`
|
||||
* TypeScript (typed for Vue/TS projects): `?format=typescript`
|
||||
|
||||
Both generated clients support a shared Bearer token helper. Call `bearerSet(token)` once, the token is stored in `localStorage` under `apilite_bearer_token`, and subsequent requests automatically send `Authorization: Bearer ...`.
|
||||
|
||||
JavaScript usage example:
|
||||
|
||||
```js
|
||||
import backend from './backend.js';
|
||||
|
||||
backend.bearerSet('your-access-token');
|
||||
|
||||
backend.add(1, 2).then((response) => {
|
||||
console.log(response.data);
|
||||
});
|
||||
@ -253,6 +257,8 @@ TypeScript usage example (Vue + TS):
|
||||
```ts
|
||||
import backend from './backend';
|
||||
|
||||
backend.bearerSet('your-access-token');
|
||||
|
||||
backend.add(1, 2).then((response) => {
|
||||
console.log(response.data); // typed value based on PHP return type
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user