To make information about the authenticated user available to your pages and UI components, you usually define pageContext.user
at renderPage()
:
You can then access pageContext.user
from any UI component using usePageContext()
.
You can pass any custom pageContext
property to renderPage()
, see API > pageContext
> Custom.
In principle, you can use Vike with any authentication tool such as:
Login flow
By using guard()
with throw redirect()
or throw render()
you can:
- Implement login flows.
- Protect private pages from unprivileged access.
Using render('/login')
instead of redirect('/login')
allows the URL to be preserved during the entire login flow:
- Unauthenticated user goes to URL
/admin
and sees the login page. (URL is /admin
.)
- User fills the sign-in form and successfully logs in. (URL is still
/admin
.)
- Reload the page, the user now sees the admin page. (URL is still
/admin
.)
See example.
You can also define a guard()
hook that applies to multiple pages:
See also