Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to destroy jwt token on logout at server side php #540

Closed
gamotmohit opened this issue Oct 19, 2023 · 2 comments
Closed

how to destroy jwt token on logout at server side php #540

gamotmohit opened this issue Oct 19, 2023 · 2 comments

Comments

@gamotmohit
Copy link

gamotmohit commented Oct 19, 2023

There is no code available which can tell how can we destroy JWT token on server in PHP.

@GuiiSantos
Copy link

       if(isset($_SESSION['jwt_token'])) {
            unset($_SESSION['jwt_token']);
            $response = ["message" => "Destroyed session token"];
            echo json_encode($response);
        } else {
            $response = ["message" => "User is not logged in"];
            echo json_encode($response);
        }

You can use the unset function in PHP to destroy a JWT token stored in a session, as shown in your provided code. This will effectively remove the token from the session, making it invalid for future requests.

Good luck with your implementation!

@bshaffer
Copy link
Collaborator

@gamotmohit that's because the tokens are not stored anywhere by this library. So destroying them would depend on your implementation.

JWTs are created by this library in memory only. Because they are signed, the only way to destroy them would be to remove them from memory, or from whatever cache you're using.

If you have a more specific question, such as how to rotate the keys you are using to sign, try reading up on best practices for securing your application. Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants