@forgehq/login
v0.0.10
Published
This SDK provides a simple way to authenticate users with Forge.
Readme
Forge Login SDK
This SDK provides a simple way to authenticate users with Forge.
Installation
npm install @forgehq/loginUsage
Subscribe to authentication state changes.
import { authService } from '@forgehq/login';
authService.onStateChanged(user => {
if (user) {
console.log('User is logged in', user);
} else {
console.log('User is not logged in');
}
});To start the login process, call the startLogin method.
authService.startLogin(GAME_NAME);After the user has logged in, they will be redirected back to your application with a token hash parameter. You can then use this token to log the user in to your application.
const url = new URL(window.location.href);
const token = url.searchParams.get('token');
if (token) {
await authService.loginWithToken(token);
}To log the user out, call the logout method.
await authService.logout();