To get the currently authenticated user for your app, you can utilize the accounts.user()
method. This method returns a client-safe object representing the current user.
Client-Only Method
This method is client-only as it's dependent on the global window
object. If used in server-executed code, this method will throw an error.
Example Usage
Example Usage
import joystick, { accounts } from '@joystick.js/ui';
const Profile = joystick.component({
data: async (api = {}, req = {}, input = {}, instance = {}) => {
return {
user: await accounts.user(),
};
},
render: ({ props, state, data, each, when, methods }) => {
return `
<div class="profile">
<header>
<h2>Hey, ${data?.user?.name?.first}!</h2>
</header>
...
</div>
`;
},
});
export default Profile;
API
accounts.user() => promise(user: object)