add delete token request to logout - #1538
Merged
Merged
Conversation
sejas
approved these changes
Jul 9, 2025
sejas
left a comment
Member
There was a problem hiding this comment.
I sandboxed the API and tried logging out. I confirm the token is revoked and it works as expected:
wpcom-logout-deauth-token.mp4
Comment on lines
+76
to
+90
| const response = await fetch( | ||
| 'https://public-api.wordpress.com/wpcom/v2/studio-app/token', | ||
| { | ||
| method: 'DELETE', | ||
| headers: { | ||
| Authorization: `Bearer ${ token.accessToken }`, | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| signal: AbortSignal.timeout( 5000 ), | ||
| } | ||
| ); | ||
|
|
||
| if ( ! response.ok ) { | ||
| console.error( 'Failed to revoke token:', response.status, response.statusText ); | ||
| } |
Member
There was a problem hiding this comment.
ha! it seems the wpcom req.delete sends the POST method instead. In theory if you pass the method as param it should override it, but I couldn't make it work. See the code.
An alternative if we want to avoid passing the bearer token is using client.request instead which I tried it and it works. Something like:
client?.request(
{
apiNamespace: 'wpcom/v2',
method: 'DELETE',
path: '/studio-app/token',
},
( err, response ) => {
if ( err ) {
console.error( 'Failed to revoke token:', err );
}
console.log( 'Token revoked:', response );
}
);
Contributor
Author
There was a problem hiding this comment.
I also couldn't overwrite the method.
But using client.request is a great approach, thanks @sejas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issues
Proposed Changes
Testing Instructions
Pre-merge Checklist