We can add information about the authenticated user to pageContext
at the server middlware:
const renderPage = createPageRenderer(/* ... */)
// `vite-plugin-ssr` server middleware
app.get('*', async (req, res) => {
// Authentication middlewares (e.g. Passport.js or Grant) provide information
// about the logged-in user on the `req` object.
const user = req.user
/* Or when using a third-party authentication provider (e.g. Auth0):
const user = await authProviderApi.getUser(req.headers)
*/
const pageContext = {
url: req.url,
// We make logged-in user information available to pages as `pageContext.user`
user
}
const result = await renderPage(pageContext)
/* ... */
})
Common auth tools:
In principle, you can use vite-plugin-ssr
with any authentication tool. However, if you are having difficulties integrating an authentication tool, join our Discord server or open a new GitHub issue.