• How it works
  • Partners
  • Blog
  • Docs
  • Sign up
  • Client Area

Ad Publishers

  • Getting started with Ads – Common Issues & FAQs
  • Payment & Fee FAQs
  • Setting up your ads.txt file
  • Installing the ad script on your page
  • Creating an ad placement
  • US Privacy law compliance steps
  • Ad script lifecycle events
  • Detecting ad-blocking users
  • Special ad format: Sticky Stack
  • Placement Configuration API

CMP

  • Adding custom consents or disclosures
  • Creating a link for the user to manage their consents

Sponsor

  • Getting started with Sponsor

Users

  • Getting started with Users
  • Adding the Users SDK to your site
  • Initializing the Users SDK
  • Launching the login/registration screen
  • Managing user sessions
  • Users SDK API Reference
  • NitroPay
  • Docs
  • Users
  • Managing user sessions

Managing user sessions

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;
    }
}

Share this document:
  • Facebook
  • Twitter
  • LinkedIn
Updated on January 25, 2023
Launching the login/registration screenUsers SDK API Reference
© GG Software, LP
Privacy Policy | Terms of Use | Contact us