⚠️
The vite-plugin-ssr project has been renamed Vike.
  • If you are already using vite-plugin-ssr then migrate to Vike.
  • For new projects, don't use vite-plugin-ssr but use Vike instead.

Guard

The guard() hook enables you to protect pages.

The most common use cases being authentication and authorization, see Guides > Authentication > Login flow.

Note that:

  • It's always used together with throw render() or throw redirect(). (The guard() hook doesn't accept any return value.)
  • It can be asynchronous. (Unlike Route Functions which are always synchronous.)
  • A single guard() hook can apply to multiple pages. (By using the usual inheritance rules.)