How can I end a session on my webpage when I click on the X or close button on browser?

When clicking X or close button my session does’t end and I can get to my dashboard page without linking at login page. I couldn’t figure out how can I end session when I click on close(X) button. I would appreciate if you got something helpful to show me…

I can end session when I click on logout button on the navbar and I can’t get to pages without logging in and thats totally ok. What I expect to end the session when I click on close(X)
button as the same when I click on log out button.