
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
@redwoodjs/auth-dbauth-middleware
Advanced tools
import type { TagDescriptor } from '@redwoodjs/web'
import App from './App'
import initDbAuthMiddleware from '@redwoodjs/auth-dbauth-middleware'
import { Document } from './Document'
import { handler as dbAuthHandler } from '$api/src/functions/auth'
import { cookieName } from '$api/src/lib/auth'
import { getCurrentUser } from '$api/src/lib/auth'
interface Props {
css: string[]
meta?: TagDescriptor[]
}
export const registerMiddleware = () => {
// This actually returns [dbAuthMiddleware, '*']
const authMw = initDbAuthMiddleware({
dbAuthHandler,
getCurrentUser,
// cookieName optional
// getRoles optional
// dbAuthUrl? optional
})
return [authMw]
}
export const ServerEntry: React.FC<Props> = ({ css, meta }) => {
return (
<Document css={css} meta={meta}>
<App />
</Document>
)
}
By default the middleware assumes your roles will be in currentUser.roles - either as a string or an array of strings.
For example
// If this is your current user:
{
email: 'user-1@example.com',
id: 'mocked-current-user-1',
roles: 'admin'
}
// In the ServerAuthState
{
cookieHeader: 'session=session_cookie',
currentUser: {
email: 'user-1@example.com',
id: 'mocked-current-user-1',
roles: 'admin' // <-- you sent back 'admin' as string
},
hasError: false,
isAuthenticated: true,
loading: false,
userMetadata: /*..*/
roles: ['admin'] // <-- converted to array
}
You can customise this by passing a custom getRoles function into initDbAuthMiddleware. For example:
const authMw = initDbAuthMiddleware({
dbAuthHandler,
getCurrentUser,
getRoles: (decoded) => {
// Assuming you want to get roles from a property called org
if (decoded.currentUser.org) {
return [decoded.currentUser.org]
} else {
return []
}
},
})
FAQs
Unknown package
We found that @redwoodjs/auth-dbauth-middleware demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.