VitNode

States from Backend

Learn how to use states from the backend in the frontend.

Middleware Data State

This state is used to get the middleware data from the server like:

  • Available languages,
  • Global settings: title, description, etc.
  • Plugins code,
  • Middleware settings, for example: editor settings, captcha provider etc.
import { getMiddlewareData } from 'vitnode-frontend/api/get-middleware-data';
 
const data = await getMiddlewareData();

User Data State

This state is used to get the user data with personal settings (for example: files settings).

import { getSessionData } from 'vitnode-frontend/api/get-session-data';
 
const data = await getSessionData();

Admin Data State

Inside admin route you cannot use getSessionData function. You need to use getAdminSessionData function.

That's because admin has different settings and permissions.

import { getSessionData } from 'vitnode-frontend/api/get-session-admin-data';
 
const data = await getSessionAdminData();

Sometimes might be useful to get the user id from the cookie. For example for tags in fetch cache.

import { getUserIdCookie } from 'vitnode-frontend/api/get-user-id-cookie';
 
const userIdFromCookie = getUserIdCookie();

On this page