After a user successfully logs in through the authorization flow, the dialog will close and session information will be posted back and stored in local storage (configurable). You can now retrieve metadata about the user and perform the UI updates needed to accommodate their membership.
In JavaScript if you want to pull the information on the currently logged in user, you could write:
users.currentUser().then(function (user) {
// Access to User entity now available
});
If you’re using modules, you may prefer to make a class to manage sessions. A complete example of instantiating the client and performing the most basic API commands is available here:
import { Auth } from '@nitropay/sdk/src/auth';
import { User, UsersClient } from '@nitropay/sdk/src/users';
export class SessionService {
auth: Auth;
currentUser: User;
users: UsersClient;
constructor() {
this.auth = new Auth({ clientId: 'YourClientId', scope: 'openid offline' });
this.users = new UsersClient(this.auth);
}
async load(): Promise<void> {
this.currentUser = await this.users.currentUser();
}
async login(): Promise<void> {
await this.auth.authorize();
await this.load();
}
async logout(): Promise<void> {
await this.auth.logout();
this.currentUser = null;
}
}