Private
accessPrivate
apiPrivate
apiPrivate
clientPrivate
fiefPrivate
fiefPrivate
forbiddenPrivate
loginPrivate
logoutPrivate
logoutPrivate
redirectPrivate
redirectURIPrivate
returnPrivate
returnPrivate
sessionPrivate
userReturn an API middleware to authenticate an API route.
Your API route handler.
Optional parameters to apply when authenticating the request.
An API handler.
Basic
import { fiefAuth } from "../../fief"
export default fiefAuth.authenticated(function handler(req, res) {
res.status(200).json(req.user);
});
Required scope
import { fiefAuth } from "../../fief"
export default fiefAuth.authenticated(function handler(req, res) {
res.status(200).json(req.user);
}, { scope: ['required_scope'] });
Minimum ACR level
import { fiefAuth } from "../../fief"
export default fiefAuth.authenticated(function handler(req, res) {
res.status(200).json(req.user);
}, { acr: FiefACR.LEVEL_ONE });
Required permissions
import { fiefAuth } from "../../fief"
export default fiefAuth.authenticated(function handler(req, res) {
res.status(200).json(req.user);
}, { permissions: ['castles:create'] });
Return an API route to get the FiefUserInfo and FiefAccessTokenInfo of the currently authenticated user.
It's mainly useful to get the user information from the React hooks.
An API route.
import { fiefAuth } from '../../fief';
export default fiefAuth.currentUser();
Return a Next.js middleware to control authentication on the specified paths.
A list of paths matchers with their authentication parameters.
A Next.js middleware function.
import type { NextRequest } from 'next/server'
import { fiefAuth } from './fief'
const authMiddleware = fiefAuth.middleware([
{
matcher: '/private',
parameters: {},
},
{
matcher: '/app/:path*',
parameters: {},
},
{
matcher: '/scope',
parameters: {
scope: ['required_scope'],
},
},
{
matcher: '/acr',
parameters: {
acr: FiefACR.LEVEL_ONE,
},
},
{
matcher: '/permission',
parameters: {
permissions: ['castles:create'],
},
},
]);
export async function middleware(request: NextRequest) {
return authMiddleware(request);
};
Generated using TypeDoc
Helper class to integrate Fief authentication with Next.js.
Example
Basic