/saaskit:implement-access-controlfrom saaskit
Implements roles and permissions at a route so an agent can protect an endpoint. Use when the user wants roles, permissions, or RBAC. It does not write SaaSKit login (that's `implement-saaskit`).
Ships in saaskit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Put roles and permissions on a route. Then stop.
validateToken before reading roles or permissions.requireRole / requirePermission.implement-saaskit instead.implement-saaskit for login. Still write the guards.implement-saaskit.SCALEKIT_ENVIRONMENT_URL, SCALEKIT_CLIENT_ID, SCALEKIT_CLIENT_SECRET. Never SCALEKIT_ENV_URL.req.cookies.accessToken as-is (path: '/api'). Do not decrypt unless manage-saaskit-sessions already encrypts that same cookie.getSession().accessToken from scalekit_session. Do not add an accessToken cookie.user["roles"] from requires_auth. Do not add an accessToken cookie.validateToken validates and returns claims. Do not decode the JWT yourself. Node has no validateAccessTokenAndGetClaims.roles and permissions are string arrays. sub is the user. oid is the org.admin to the first user in an org and member to the rest.resource:action (example: projects:read)./api/* so the Express access cookie is sent. SPA: read Authorization: Bearer instead.If the app has no SaaSKit login, name implement-saaskit for login. Still write the route guards here. Do not write login.
accessToken cookie.getSession().accessToken from scalekit_session.user["roles"] from requires_auth.Print this checklist. Ask the human to write missing SCALEKIT_ENVIRONMENT_URL, SCALEKIT_CLIENT_ID, and SCALEKIT_CLIENT_SECRET into .env. Then write the guards.
admin and member exist. Add a permission such as projects:read only if the route needs one.Do not invent role names. Do not invent those env values.
Done when: this skill is the right path, implement-saaskit is named if login is missing, and the three env names exist.
Install @scalekit-sdk/node only when the repo has no Scalekit SDK yet. Reuse cookieParser() from implement-saaskit.
import { ScalekitClient } from '@scalekit-sdk/node';
const scalekit = new ScalekitClient(
process.env.SCALEKIT_ENVIRONMENT_URL,
process.env.SCALEKIT_CLIENT_ID,
process.env.SCALEKIT_CLIENT_SECRET
);
Done when: the client initializes from those env vars.
export async function requireAuth(req, res, next) {
const accessToken = req.cookies?.accessToken;
if (!accessToken) {
return res.status(401).json({ error: 'Authentication required' });
}
try {
const claims = await scalekit.validateToken(accessToken);
req.user = {
id: claims.sub,
organizationId: claims.oid,
roles: claims.roles || [],
permissions: claims.permissions || [],
};
return next();
} catch {
return res.status(401).json({ error: 'Authentication failed' });
}
}
SPA: read the Bearer token from Authorization instead of the cookie.
Done when: a missing token returns 401, and a valid token sets req.user.roles and req.user.permissions.
const hasRole = (user, role) => user.roles?.includes(role);
const requireRole = (role) => (req, res, next) =>
hasRole(req.user, role)
? next()
: res.status(403).json({ error: `Access denied. Required role: ${role}` });
const hasPermission = (user, perm) => user.permissions?.includes(perm);
const requirePermission = (perm) => (req, res, next) =>
hasPermission(req.user, perm)
? next()
: res.status(403).json({ error: `Access denied. Required permission: ${perm}` });
app.get('/api/admin/users', requireAuth, requireRole('admin'), (req, res) => {
res.json({ ok: true, org: req.user.organizationId });
});
app.get('/api/projects', requireAuth, requirePermission('projects:read'), (req, res) => {
res.json({ ok: true, org: req.user.organizationId });
});
Mount requireAuth before the role or permission guard.
Done when: those two GET routes exist and the guards run before the handler.
Use GET. Send the same cookie the browser has after login.
curl -H "Cookie: accessToken=<cookie_from_login>" http://localhost:3000/api/admin/users
# admin session → 200
# member session → 403
curl http://localhost:3000/api/admin/users
# missing token → 401
Done when: admin is 200, member is 403, and a missing token is 401.
Do not write login. Do not add refresh or revoke.
Done when: a route checks a role or permission, the curls match Step 5, and this skill has stopped.
implement-saaskit for login, callback, cookies, and logoutmanage-saaskit-sessions to store, validate, refresh, or revokeimplement-scim to provision users from a directoryWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub scalekit-inc/authstack --plugin saaskit15 skills in this plugin
/add-api-authAdds API key or client-credentials auth so an agent can protect an API. Use when the user wants an API key or client credentials. It does not put OAuth 2.1 on an MCP server (that's `add-mcp-oauth`) or write SaaSKit login (that's `implement-saaskit`).
/add-mcp-oauthAdds MCP OAuth so an agent can protect the user's MCP server. Use when the user wants MCP OAuth or to protect their MCP server. It does not add API keys or client credentials (that's `add-api-auth`) or expose AgentKit tools over MCP (that's `expose-agentkit-mcp`).
/check-saaskit-prodChecks SaaSKit production so an agent can finish a go-live checklist. Use when the user wants SaaSKit production or to go live SaaSKit. It does not write login (that's `implement-saaskit`) or run dryrun (that's `run-dryrun`).
Other plugins' skills for the same job