Custom log out problem on a Dynamic member page

Hey!

So I’ve created a custom member area for my site, and have not used the Wix native one. My problem is more or less a bug in my opinion but it frustrates me a bit so I’m curious if it’s a code problem from my side or it’s because you can’t do a workaround in some cases.
I’m using a button for login or log out and it works perfectly fine on every page except on the user dynamic page because when I want to log out it does not take me to my homepage but redirects me to Wix native login/register page, and when only after I close this page, then it shows my homepage and I’m not quite sure why the code doing this only on my dynamic user page.

Thats the code from the masterPage.js file

import { session } from ‘wix-storage’ ;
import wixLocation from ‘wix-location’ ;
import wixData from ‘wix-data’ ;
import wixUsers from ‘wix-users’ ;
import { authentication } from ‘wix-members’ ;

//log in / log out button labels and changes

$w . onReady (() => {
if ( wixUsers.currentUser.loggedIn ) {
$w ( “#loginbutton” ). label = “Kijelentkezés” ;
$w ( “#ProfileButton” ). show ();
$w ( “#secretlogbutton” ). hide ()
} else {
$w ( “#loginbutton” ). label = “Bejelentkezés” ;
$w ( “#ProfileButton” ). hide ();
$w ( “#secretlogbutton” ). show ();
$w ( “#loginbutton” ). hide ();
}

$w . onReady ( function (){
$w ( ‘#loginbutton’ ). onClick ( event => {
// user is logged in
if ( wixUsers.currentUser.loggedIn ) {
// log the user out
authentication . logout ()
. then (() =>
{
// update buttons accordingly
$w ( “#loginbutton” ). label = “Bejelentkezés” ;
$w ( “#ProfileButton” ). hide ();
$w ( “#loginbutton” ). hide ();
$w ( “#secretlogbutton” ). show ();
});
}

})})});