Logout Web User
Last updated
Last updated
The logout event provides the functionality to logout users of your app. In this article we are going to show you how you can set up the logout event in 5 quick steps.
Step 1. create a logout endpoint
Step 2. create a logout action
Step 3. add the logout event
Step 4. build your code and test
Head over to the endpoint tab and create a new endpoint called "Logout user", with the path "/v1/logout_user", description "Logout users of my app" and the request method set to "Get". An example of this is shown below.
Save your endpoint and close it.
Next, from inside the actions tab, create an action called "Logout user" and associate the trigger component with the logout endpoint that we created in step 1.
Add the logout event to the "logout action" that we created in step 2. You can do this by clicking on the + Add Event button, as shown below.
Make sure that you save your action and close it.
The final step is to build your code and test it. To build your code click "Build code". Once the code has built, you can test it from inside the "Logout user" endpoint that we created in Step 1. Opening up the endpoint and clicking "Run" will allow you to test.
If your "Logout event" has run correctly, you'll see a Response Code 200.
To test this event more rigorously you can also follow the steps below.
Create a login event, you can read how to set up the Login Event here.
Create some endpoints that require authentication.
Test the endpoints that require authentication without first logging in. You should get a 401 error message. You can read about password protected endpoints in this article here.
Login a user and re-test the endpoints that require authentication. You should get a 200 success message, since the user is now logged in.
Create a logout event, as explained in this article.
Run your logout user endpoint again and re-test your endpoints that require authentication. You'll see these now return a 401 message, since the user is logged out..