2022-10-30 16:28:14 +08:00
|
|
|
<script>
|
|
|
|
import CodeBlock from "@/components/base/CodeBlock.svelte";
|
2023-05-20 10:58:52 +08:00
|
|
|
import FieldsQueryParam from "@/components/collections/docs/FieldsQueryParam.svelte";
|
2024-09-30 00:23:19 +08:00
|
|
|
import SdkTabs from "@/components/base/SdkTabs.svelte";
|
|
|
|
import ApiClient from "@/utils/ApiClient";
|
|
|
|
import CommonHelper from "@/utils/CommonHelper";
|
2022-10-30 16:28:14 +08:00
|
|
|
|
2023-08-15 02:20:49 +08:00
|
|
|
export let collection;
|
2022-10-30 16:28:14 +08:00
|
|
|
|
|
|
|
let responseTab = 200;
|
|
|
|
let responses = [];
|
|
|
|
|
2024-09-30 00:23:19 +08:00
|
|
|
$: backendAbsUrl = CommonHelper.getApiExampleUrl(ApiClient.baseURL);
|
2022-10-30 16:28:14 +08:00
|
|
|
|
|
|
|
$: responses = [
|
|
|
|
{
|
|
|
|
code: 200,
|
|
|
|
body: JSON.stringify(
|
|
|
|
{
|
|
|
|
token: "JWT_TOKEN",
|
|
|
|
record: CommonHelper.dummyCollectionRecord(collection),
|
|
|
|
},
|
|
|
|
null,
|
2024-09-30 00:23:19 +08:00
|
|
|
2,
|
2022-10-30 16:28:14 +08:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 401,
|
|
|
|
body: `
|
|
|
|
{
|
|
|
|
"code": 401,
|
|
|
|
"message": "The request requires valid record authorization token to be set.",
|
|
|
|
"data": {}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 403,
|
|
|
|
body: `
|
|
|
|
{
|
|
|
|
"code": 403,
|
|
|
|
"message": "The authorized record model is not allowed to perform this action.",
|
|
|
|
"data": {}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
},
|
2022-11-13 06:38:18 +08:00
|
|
|
{
|
|
|
|
code: 404,
|
|
|
|
body: `
|
|
|
|
{
|
|
|
|
"code": 404,
|
|
|
|
"message": "Missing auth record context.",
|
|
|
|
"data": {}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
},
|
2022-10-30 16:28:14 +08:00
|
|
|
];
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<h3 class="m-b-sm">Auth refresh ({collection.name})</h3>
|
|
|
|
<div class="content txt-lg m-b-sm">
|
|
|
|
<p>
|
2022-11-13 06:38:18 +08:00
|
|
|
Returns a new auth response (token and record data) for an
|
2022-10-30 16:28:14 +08:00
|
|
|
<strong>already authenticated record</strong>.
|
|
|
|
</p>
|
|
|
|
<p>
|
2024-09-30 00:23:19 +08:00
|
|
|
This method is usually called by users on page/screen reload to ensure that the previously stored data
|
|
|
|
in <code>pb.authStore</code> is still valid and up-to-date.
|
2022-10-30 16:28:14 +08:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<SdkTabs
|
|
|
|
js={`
|
|
|
|
import PocketBase from 'pocketbase';
|
|
|
|
|
|
|
|
const pb = new PocketBase('${backendAbsUrl}');
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
const authData = await pb.collection('${collection?.name}').authRefresh();
|
|
|
|
|
|
|
|
// after the above you can also access the refreshed auth data from the authStore
|
|
|
|
console.log(pb.authStore.isValid);
|
|
|
|
console.log(pb.authStore.token);
|
2024-09-30 00:23:19 +08:00
|
|
|
console.log(pb.authStore.record.id);
|
2022-10-30 16:28:14 +08:00
|
|
|
`}
|
|
|
|
dart={`
|
|
|
|
import 'package:pocketbase/pocketbase.dart';
|
|
|
|
|
|
|
|
final pb = PocketBase('${backendAbsUrl}');
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
final authData = await pb.collection('${collection?.name}').authRefresh();
|
|
|
|
|
|
|
|
// after the above you can also access the refreshed auth data from the authStore
|
|
|
|
print(pb.authStore.isValid);
|
|
|
|
print(pb.authStore.token);
|
2024-09-30 00:23:19 +08:00
|
|
|
print(pb.authStore.record.id);
|
2022-10-30 16:28:14 +08:00
|
|
|
`}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<h6 class="m-b-xs">API details</h6>
|
|
|
|
<div class="alert alert-success">
|
|
|
|
<strong class="label label-primary">POST</strong>
|
|
|
|
<div class="content">
|
|
|
|
<p>
|
|
|
|
/api/collections/<strong>{collection.name}</strong>/auth-refresh
|
|
|
|
</p>
|
|
|
|
</div>
|
2024-09-30 00:23:19 +08:00
|
|
|
<p class="txt-hint txt-sm txt-right">Requires <code>Authorization:TOKEN</code> header</p>
|
2022-10-30 16:28:14 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="section-title">Query parameters</div>
|
|
|
|
<table class="table-compact table-border m-b-base">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Param</th>
|
|
|
|
<th>Type</th>
|
|
|
|
<th width="60%">Description</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>expand</td>
|
|
|
|
<td>
|
|
|
|
<span class="label">String</span>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
Auto expand record relations. Ex.:
|
|
|
|
<CodeBlock content={`?expand=relField1,relField2.subRelField`} />
|
|
|
|
Supports up to 6-levels depth nested relations expansion. <br />
|
|
|
|
The expanded relations will be appended to the record under the
|
|
|
|
<code>expand</code> property (eg. <code>{`"expand": {"relField1": {...}, ...}`}</code>).
|
|
|
|
<br />
|
2022-11-13 06:38:18 +08:00
|
|
|
Only the relations to which the request user has permissions to <strong>view</strong> will be expanded.
|
2022-10-30 16:28:14 +08:00
|
|
|
</td>
|
|
|
|
</tr>
|
2023-12-30 05:31:54 +08:00
|
|
|
<FieldsQueryParam prefix="record." />
|
2022-10-30 16:28:14 +08:00
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<div class="section-title">Responses</div>
|
|
|
|
<div class="tabs">
|
2023-09-01 17:44:43 +08:00
|
|
|
<div class="tabs-header compact combined left">
|
2022-10-30 16:28:14 +08:00
|
|
|
{#each responses as response (response.code)}
|
|
|
|
<button
|
|
|
|
class="tab-item"
|
|
|
|
class:active={responseTab === response.code}
|
|
|
|
on:click={() => (responseTab = response.code)}
|
|
|
|
>
|
|
|
|
{response.code}
|
|
|
|
</button>
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
<div class="tabs-content">
|
|
|
|
{#each responses as response (response.code)}
|
|
|
|
<div class="tab-item" class:active={responseTab === response.code}>
|
|
|
|
<CodeBlock content={response.body} />
|
|
|
|
</div>
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
</div>
|