
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
nitro-better-auth
Advanced tools
[](https://npmjs.com/package/nitro-better-auth) []
Add dependencies to your project
pnpm add nitro-better-auth better-auth
npm install nitro-better-auth better-auth
Add module in your nitro.config.ts
export default defineNitroConfig({
modules: ['nitro-better-auth'],
betterAuth: {
// [Optional]
},
})
[!TIP] When you are using Postgresql as database with Hyperdrive in Cloudflare Worker, you should setup server singleton by request.
export default defineNitroConfig({
modules: ['nuxt-better-auth'],
// Setup server singleton by request
betterAuth: {
singleton: 'request',
},
// [Optional] Enable async context: https://nitro.build/guide/utils#async-context-experimental
experimental: {
asyncContext: true,
},
})
You can easily get betterAuth instance through useBetterAuth in the eventHandler.
export default eventHandler(async () => {
const betterAuth = useBetterAuth()
// Do something with betterAuth
// e.g: call login with anonymous
const resp = await betterAuth.api.signInAnonymous()
return {
success: true,
data: resp,
}
})
If use singleton for request, please put event to useBetterAuth, or used asyncContext first then you don't need that anymore.
export default eventHandler(async () => {
const betterAuth = useBetterAuth(event)
// Do something with betterAuth
// e.g: call login with anonymous
const resp = await betterAuth.api.signInAnonymous()
return {
success: true,
data: resp,
}
})
Create file at nitro's server dir (default is server/), e.g: server/better-auth/server-options.ts.
import type { BetterAuthOptions } from 'better-auth'
import { anonymous } from 'better-auth/plugins'
export default () => ({
plugins: [
anonymous(),
],
} satisfies BetterAuthOptions)
Provide middleware for auth, you can easy use in eventHandler
export default eventHandler({
onRequest: [
AuthenticateMiddleware, // a.k.a: AuthMiddleware
],
handler: async (event) => {
// Could get auth data form event.context
const { user } = event.context.auth!
return {
data: user,
}
},
})
Made with ❤️
Published under the MIT License.
FAQs
[](https://npmjs.com/package/nitro-better-auth) []
We found that nitro-better-auth demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.