supaapps-auth
raw JSON → 3.2.2 verified Sat Apr 25 auth: no javascript
Authentication library for SupaApps projects. Current version 3.2.2, providing token management, OAuth login flows (Google), and token validation. It uses a singleton pattern via AuthManager and supports ESM imports with TypeScript types included. Differentiators include simple API with login URI generation, access token decoding, and Bearer token validation. Release cadence is not specified but likely follows SupaApps updates.
Common errors
error Cannot find module 'supaapps-auth' or its corresponding type declarations. ↓
cause Package not installed or TypeScript unable to resolve types (though types are shipped).
fix
Run npm install supaapps-auth and ensure tsconfig.json includes 'node_modules/@types' or the package's types.
error TypeError: supaapps_auth_1.AuthManager is not a constructor ↓
cause Using default import instead of named import.
fix
Use import { AuthManager } from 'supaapps-auth' instead of import AuthManager from 'supaapps-auth'.
error Error: authManager.mustBeLoggedIn is not a function ↓
cause Calling mustBeLoggedIn on undefined or wrong object (e.g., using getInstance() before constructor).
fix
Ensure AuthManager is instantiated or getInstance() is called after construction.
Warnings
gotcha mustBeLoggedIn() may return false even if token is valid if token is not in local storage ↓
fix Ensure token is stored via setAccessToken() or login flow.
gotcha new AuthManager() constructs a new instance, but getInstance() returns a singleton. Mixing patterns may cause multiple API calls. ↓
fix Use AuthManager.getInstance() after initial construction, or consistently use constructor without getInstance.
deprecated validateToken() may be deprecated in future versions; check docs ↓
fix Use AuthManager.validateToken() as shown, but monitor for replacement.
gotcha getLoginWithGoogleUri() returns a URI, but does not automatically redirect; developer must handle navigation. ↓
fix Assign window.location.href to the URI, or use an anchor tag.
Install
npm install supaapps-auth yarn add supaapps-auth pnpm add supaapps-auth Imports
- AuthManager wrong
import AuthManager from 'supaapps-auth'correctimport { AuthManager } from 'supaapps-auth' - AuthManager (type)
import type { AuthManager } from 'supaapps-auth' - AuthManager (namespace)
import { AuthManager as AM } from 'supaapps-auth'
Quickstart
import { AuthManager } from 'supaapps-auth';
const authManager = new AuthManager(
'https://supaapps-auth-api.testing.sacl.io/',
'root',
'http://localhost:3001/exchange',
() => { console.log('redirect to login'); }
);
// Check if user must be logged in
authManager.mustBeLoggedIn().then((isLoggedIn) => {
if (isLoggedIn) {
// Proceed
} else {
authManager.getLoginWithGoogleUri().then((uri) => {
window.location.href = uri;
});
}
});
// Logout
authManager.logout().then(() => {
console.log('Logged out');
});