How to auto-redirect to login after an unauthorized api request (ex. when token has expired, error 401)? - Nuxt Auth module

How to auto-redirect to login after an unauthorized api request (ex. when token has expired, error 401)? - Nuxt Auth module.

Please Guys I need Help with this, been having issues and all I have been doing seems not to work…

export default function ({ $auth, redirect, route, store }) {
if (!$auth.user || !$auth.loggedIn || !$auth.user.role.includes(‘admin’)) {
return redirect(’/admin/login?r=’ + route.fullPath.replace(’/admin/’, ‘’))
}
}

Thanks