To check whether or not there's a currently authenticated user, you can utilize the accounts.authenticated() method. This method returns a Boolean response of either true or false.
How to Get the Authenticated User
If you'd like to get the full, currently authenticated user, you can utilize the accounts.user() method defined here.
Example Usage
Example Usage
import joystick, { accounts } from '@joystick.js/ui';
const Dashboard = joystick.component({
events: {
'click .logout': async (event = {}, instance = {}) => {
if (await accounts.authenticated()) {
await accounts.logout();
location.pathname = '/login';
}
},
},
render: ({ props, state, data, each, when, methods }) => {
return `
<div class="dashboard">
<nav>
<a href="/"><img src="/logo.svg" alt="Brand" /></a>
<ul>
<li><a href="/">Dashboard</a></li>
<li><a href="/friends">Friends</a></li>
<li><a href="/messages">Messages</a></li>
<li class="logout"><a href="#">Logout</a></li>
</ul>
</nav>
</div>
`;
},
});
export default Dashboard;
API
accounts.authenticated() => promise(boolean)