⚠
vite-plugin-ssr has been renamed Vike, see migration guide.

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.)