The Auth.js configuration
A middleware function that handles authentication by intercepting requests to the Auth.js callbacks
@auth/core
package to use this middleware. It contains the providers.AUTH_SECRET
in your environment variables.AUTH_BASE_PATH
environment variable can be used to set the base path for the Auth.js routes. The default is /api/auth
.Example usage:
import { start, router, authMiddleware, text } from "@pulsar-http/core";
import githubAuthProvider from '@auth/core/providers/github';
const routes = [
router.get("/", async () => text("Hello world")),
];
const auth = authMiddleware({
providers: [
githubAuthProvider({
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET"
}),
]
});
start({
routes,
middlewares: [auth],
});
In this example, the auth
middleware is added to the server, which will handle authentication for the GitHub provider.
If you access the /api/auth/signin route, the user will be redirected to a page containing a link to sign in with GitHub.
Middleware to authenticate users with Auth.js