Skip to content

setPassword with POST from JS app frontend template instead of craft link #9549

Answered by brandonkelly
steveDL asked this question in Q&A
Discussion options

You must be logged in to vote

For handling set-password requests coming from verification emails, first you’ll need to change your setPasswordPath config setting to the absolute URL of whatever page you want to show the password form on.

Then in JS on the page, fetch the id andcode query string params. (id will be the user’s UID, not their numerical ID.)

Display a password form, and on submit, send a POST request to Craft’s users/set-password action:

try {
    const response = await axios.post(`${this.apiUrl}actions/users/set-password`, {
        code: code,
        id: id,
        newPassword: 'new-password',
    });

    if (typeof response.data.error !== 'undefined') {
        throw response.data.error;
    }
} catch 

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@steveDL
Comment options

@steveDL
Comment options

@steveDL
Comment options

@steveDL
Comment options

@brandonkelly
Comment options

Comment options

You must be logged in to vote
1 reply
@steveDL
Comment options

Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants
Converted from issue

This discussion was converted from issue #9548 on July 13, 2021 13:56.