Logout Web User

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

Step 1. create a logout endpoint

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.

Step 2. create a logout action

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.

Step 3. add the logout event

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.

Step 4. build your code and test

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.

  1. Create a login event, you can read how to set up the Login Event here.

  2. Create some endpoints that require authentication.

  3. 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.

  4. 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.

  5. Create a logout event, as explained in this article.

  6. 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..

Last updated