mirror of
https://github.com/pocketbase/pocketbase.git
synced 2026-05-19 06:11:43 -04:00
99 lines
7.1 KiB
JavaScript
99 lines
7.1 KiB
JavaScript
function e(e){let i=app.utils.getApiExampleURL(),a=[{title:`Request email change`,content:n},{title:`Confirm email change`,content:r}],o=store({activeActionIndex:0});return t.div({pbEvent:`apiPreviewEmailChange`,className:`content`},t.p(null,`Sends ${e.name} email change request.`),t.p(null,`On successful email change all previously issued auth tokens for the specific record will be invalidated (and the user will be marked as verified if not already).`),app.components.codeBlockTabs({className:`sdk-examples m-t-sm`,historyKey:`pbLastSDK`,tabs:[{title:`JS SDK`,language:`js`,value:`
|
|
import PocketBase from 'pocketbase';
|
|
|
|
const pb = new PocketBase('${i}');
|
|
|
|
...
|
|
|
|
await pb.collection('${e.name}').authWithPassword(
|
|
'test@example.com',
|
|
'1234567890'
|
|
);
|
|
|
|
await pb.collection('${e.name}').requestEmailChange('new@example.com');
|
|
|
|
// ---
|
|
// (optional) in your custom confirmation page:
|
|
// ---
|
|
|
|
// note: all previous user auth tokens will be invalidated
|
|
// (and the user will be marked as verified if not already)
|
|
await pb.collection('${e.name}').confirmEmailChange(
|
|
'EMAIL_CHANGE_TOKEN',
|
|
'YOUR_PASSWORD',
|
|
);
|
|
`,footnote:t.div({className:`txt-right`},t.a({href:`https://github.com/pocketbase/js-sdk`,target:`_blank`,rel:`noopener noreferrer`,textContent:`JS SDK docs`}))},{title:`Dart SDK`,language:`dart`,value:`
|
|
import 'package:pocketbase/pocketbase.dart';
|
|
|
|
final pb = PocketBase('${i}');
|
|
|
|
...
|
|
|
|
await pb.collection('${e.name}').authWithPassword(
|
|
'test@example.com',
|
|
'1234567890'
|
|
);
|
|
|
|
await pb.collection('${e.name}').requestEmailChange('new@example.com');
|
|
|
|
// ---
|
|
// (optional) in your custom confirmation page:
|
|
// ---
|
|
|
|
// note: all previous user auth tokens will be invalidated
|
|
// (and the user will be marked as verified if not already)
|
|
await pb.collection('${e.name}').confirmEmailChange(
|
|
'EMAIL_CHANGE_TOKEN',
|
|
'YOUR_PASSWORD',
|
|
);
|
|
`,footnote:t.div({className:`txt-right`},t.a({href:`https://github.com/pocketbase/dart-sdk`,target:`_blank`,rel:`noopener noreferrer`,textContent:`Dart SDK docs`}))},{title:`curl`,language:`bash`,value:`
|
|
# Request email change
|
|
curl -X POST \\
|
|
-H 'Authorization:TOKEN' \\
|
|
-H 'Content-Type:application/json' \\
|
|
-d '{ "newEmail":"..." }' \\
|
|
'${i}/api/collections/${e.name}/request-email-change'
|
|
|
|
# Confirm email change
|
|
#
|
|
# note: all previous user auth tokens will be invalidated
|
|
# (and the user will be marked as verified if not already)
|
|
curl -X POST \\
|
|
-H 'Content-Type:application/json' \\
|
|
-d '{ "token":"...", "password":"" }' \\
|
|
'${i}/api/collections/${e.name}/confirm-email-change'
|
|
`}]}),t.nav({className:`btns m-t-base m-b-sm`},()=>a.map((e,n)=>t.button({type:`button`,className:()=>`btn sm expanded ${o.activeActionIndex==n?`active`:`secondary`}`,textContent:()=>e.title,onclick:()=>o.activeActionIndex=n}))),()=>a[o.activeActionIndex]?.content?.(e))}function n(e){return[t.div({className:`block`},t.strong(null,`API details`)),t.div({className:`alert success api-preview-alert`},t.span({className:`label method`},`POST`),t.span({className:`path`},`/api/collections/${e.name}/request-email-change`),t.small({className:`extra`},`Requires`,t.br(),`Authorization:TOKEN header`)),t.table({className:`api-preview-table body-params`},t.thead(null,t.tr(null,t.th({className:`min-width txt-primary`},`Body params`),t.th({className:`min-width`},`Type`),t.th(null,`Description`))),t.tbody(null,t.tr(null,t.td({className:`min-width`},`newEmail `,t.em(null,`(required)`)),t.td({className:`min-width`},t.span({className:`label`},`String`)),t.td(null,`The new email address to send the change email request.`)))),t.div({className:`block m-t-base m-b-sm`},t.strong(null,`Example responses`)),app.components.codeBlockTabs({tabs:[{title:204,value:`null`},{title:400,value:`
|
|
{
|
|
"status": 400,
|
|
"message": "An error occurred while validating the submitted data.",
|
|
"data": {
|
|
"newEmail": {
|
|
"code": "validation_required",
|
|
"message": "Missing required value."
|
|
}
|
|
}
|
|
}
|
|
`},{title:401,value:`
|
|
{
|
|
"status": 401,
|
|
"message": "The request requires valid record authorization token to be set.",
|
|
"data": {}
|
|
}
|
|
`},{title:403,value:`
|
|
{
|
|
"status": 403,
|
|
"message": "The authorized record model is not allowed to perform this action.",
|
|
"data": {}
|
|
}
|
|
`}]})]}function r(e){return[t.div({className:`block`},t.strong(null,`API details`)),t.div({className:`alert success api-preview-alert`},t.span({className:`label method`},`POST`),t.span({className:`path`},`/api/collections/${e.name}/confirm-email-change`)),t.table({className:`api-preview-table body-params`},t.thead(null,t.tr(null,t.th({className:`min-width txt-primary`},`Body params`),t.th({className:`min-width`},`Type`),t.th(null,`Description`))),t.tbody(null,t.tr(null,t.td({className:`min-width`},`token `,t.em(null,`(required)`)),t.td({className:`min-width`},t.span({className:`label`},`String`)),t.td(null,`The token from the change email request email.`)),t.tr(null,t.td({className:`min-width`},`password `,t.em(null,`(required)`)),t.td({className:`min-width`},t.span({className:`label`},`String`)),t.td(null,`The account password to confirm the email change.`)))),t.div({className:`block m-t-base m-b-sm`},t.strong(null,`Example responses`)),app.components.codeBlockTabs({tabs:[{title:204,value:`null`},{title:400,value:`
|
|
{
|
|
"status": 400,
|
|
"message": "An error occurred while validating the submitted data.",
|
|
"data": {
|
|
"token": {
|
|
"code": "validation_required",
|
|
"message": "Missing required value."
|
|
}
|
|
}
|
|
}
|
|
`}]})]}export{e as docsEmailChange}; |