Streamplace Auth Plugin
raw JSON → 0.1.10 verified Sat Apr 25 auth: no javascript
An authentication plugin for Streamplace, an open-source live streaming platform. This package provides authentication middleware and utilities for Streamplace plugins. Version 0.1.10 is prerelease with no stable release cadence yet. It is designed specifically for the Streamplace ecosystem and not intended for general use. Differentiators include simple integration with Streamplace's plugin system and built-in session management.
Common errors
error Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'sp-core' imported from .../sp-plugin-auth/build/index.js ↓
cause The package requires sp-core as a peer dependency, but it is not installed.
fix
Run
npm install sp-core as a dependency in your project. error TypeError: authPlugin is not a function ↓
cause Using the old import style (e.g., `const authPlugin = require('sp-plugin-auth')`) which yields an object, not a callable function.
fix
Update to
import authPlugin from 'sp-plugin-auth' and call it as a function. error Property 'user' does not exist on type 'Request'. ↓
cause TypeScript cannot find the augmented Express Request type because Streamplace type definitions are missing.
fix
Ensure 'sp-core' is installed and a tsconfig includes its types, or add a local type declaration.
Warnings
breaking v0.1.0 changed the default export from an object to a function. Update import: `import authPlugin from 'sp-plugin-auth'` instead of `const authPlugin = require('sp-plugin-auth')` or `import * as authPlugin from 'sp-plugin-auth'`. ↓
fix Use default import syntax and call the function with config.
deprecated The `session` option in AuthConfig has been deprecated in favor of using express-session directly as middleware. Setting session in config will be removed in the next major version. ↓
fix Remove `session` from config and add express-session middleware before the auth plugin.
gotcha Session middleware (express-session) must be applied before sp-plugin-auth. Otherwise, the plugin cannot initialize the session store. ↓
fix Ensure `app.use(session(...))` is called before `app.use(authPlugin(...))`.
gotcha When using TypeScript, the `req.user` type is augmented globally. You must include a tsconfig with Streamplace types, or you may get `Property 'user' does not exist on type 'Request'`. ↓
fix Reference Streamplace type definitions by importing 'sp-core' or adding `/// <reference types="sp-core" />`.
gotcha The plugin uses async callback handlers. Errors thrown in callbacks are not caught by Express unless you wrap them or use an error-handling middleware. ↓
fix Wrap route handlers in `try/catch` or use a package like `express-async-errors`.
Install
npm install sp-plugin-auth yarn add sp-plugin-auth pnpm add sp-plugin-auth Imports
- default
import authPlugin from 'sp-plugin-auth' - AuthConfig wrong
import { AuthConfig } from 'sp-plugin-auth'correctimport type { AuthConfig } from 'sp-plugin-auth' - createAuthMiddleware
import { createAuthMiddleware } from 'sp-plugin-auth'
Quickstart
import authPlugin from 'sp-plugin-auth';
import express from 'express';
import session from 'express-session';
const app = express();
app.use(session({ secret: process.env.SESSION_SECRET ?? 'change-me', resave: false, saveUninitialized: true }));
app.use(authPlugin({ provider: 'github', clientId: process.env.GITHUB_CLIENT_ID ?? '', clientSecret: process.env.GITHUB_CLIENT_SECRET ?? '' }));
app.get('/profile', (req, res) => {
res.json({ user: req.user });
});
app.listen(3000);