Playing Next Lesson In
seconds

Let's Learn AdonisJS 6 #7.3

Logging Out An Authenticated User

In This Lesson

We'll learn how to logout an authenticated user using a POST request with CSRF protection.

Created by
@tomgobich
Published

Join the Discussion 2 comments

Create a free account to join in on the discussion
  1. @guy-aloni

    I use access tokens, and when I do either await auth.use('api').logout() I get an error auth.use(...).logout is not a function.
    I can neither get the token explicitly using auth.use('api').token (I get undefined).

    The only way I can get it is from the request header, but I find it hard to believe that there is no way to extract it from the auth. Anyway, since the hashed token is stored, I don't even know whether the approach of searching for it in the DB will work.

    1
    1. Responding to guy-aloni
      @tomgobich

      Hi Guy! The auth process shown in this series is for session authentication. The access token auth does not contain a logout method, but rather works via the accessTokens property added onto the User model.

      There are a few key differences between session and access token auth, you can check out our Access Token Authentication in 20 Minutes lesson to see a walk-through of auth for access tokens.

      1