Add conditions for different scenarios

Keyboard Shortcuts

Stand-alone apps that use authentication with the WordPress REST API need to account for various scenarios including logged in, logged out, and other states. Learn how to use logic to provide a usable user experience for all conditions.

- [Voiceover] At this point,…the editing functionality works as expected,…but the logic in our app is not all that great.…I'll show you what I mean.…If I log in, I get my "edit title" button…and I can go in and edit the title…and save the title…and everything works fine.…But if I click "Log Out" I get my login field back…but I still have the "edit title" down here…and I can mess around with this…and then if I click "save title,"…weird things start happening.…Or basically nothing is happening.…

What I need to do now that I have all…the main components in place…is set up some logic in my script…to ensure that this mess doesn't happen.…Basically I want to hide the editing capability…when we are logged out,…and only activate it when we're logged in.…I also want to account for this scenario…on being logged in and then reloading the page…and avoiding having to log in again.…If you think about how the script currently works,…you may also see the solution.…Earlier, when we got the token…you'll remember we stashed the token…

Resume Transcript Auto-Scroll

Author

Released

6/8/2017

To unlock the full potential of the WordPress REST API, you must understand how to create, read, edit, and delete content—tasks that can be performed only with the right authorization. In this course, explore several authentication methods for the WordPress REST API. Discover what authentication is and when you need it, and explore cookie authentication and how to piggyback off of the built-in authentication system in WordPress. Plus, learn about several different credential verification methods that ensure secure communication, including JWT and OAuth 2 authentication.