The incoming request
The session data for the current request
This function needs to be used in conjunction with the authMiddleware
middleware.
Example usage:
import {start, router, authMiddleware, text, getSession} from "@pulsar-http/core";
import githubAuthProvider from '@auth/core/providers/github';
const routes = [
router.get("/", async ({ request }) => {
const session = await getSession(request);
return text(`Hello, ${session?.user?.name ?? 'guest'}!`);
}),
];
const auth = authMiddleware({
providers: [
githubAuthProvider({
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET"
}),
]
});
start({
routes,
middlewares: [auth],
});
In this example, the getSession
function is used to get the session data for the current request.
If you access the /api/auth/signin route and sign in with GitHub, the user's name will be displayed on the page.
Function to get the session data for the current request