How to destroy session

I have alogin api, and i know how to make session like below code
user = frappe.get_doc(‘User’, frappe.session.user)

but i want to destroy the session for this user using logout api, anyone know the code

Hi @Rajat96318,

Please check it.

from frappe.sessions import clear_sessions
clear_sessions(user=frappe.session.user, keep_current=True, force=True)

strange, was just seeing this code only, found in session.py file

how can i set the session to not expire by itself, like a year (8760 hours later), or months.

Like at night also, the desktop login gets expire, how to stop this
Basically, i want that through my logout api only the session expires

  1. use this syntax, then desktop user don’t get logout for a long time

  2. use this code to destroy session, basically a logout api

from frappe import _

@frappe.whitelist(allow_guest=True)
def logout(user):
    a = frappe.db.sql("""select *from `tabUser` where name=%s""", user)
    if not a:
        return "user not exist"
    
    clear_sessions(user, keep_current=False, device='desktop', force=True)
    return _("Logged out successfully")

add in hooks? and where add

Yes, using the override whitelist method.

I can’t find the whitelist method related to the location.

please check it.

right ?

override_whitelisted_methods = {
    "frappe.client.logout": "app.api.logout"
}

please, check the path of the logout method.

i cant find the path

so first you have to find the path in the core file.