-
Notifications
You must be signed in to change notification settings - Fork 0
Authentication
Andreas Ekström edited this page Jul 19, 2026
·
2 revisions
ViteWP uses WordPress-native cookie authentication on the unified site origin. Login, logout, password reset, and /wp-admin/* stay WordPress-rendered by default, while Astro SSR can read the current user without manually passing cookies:
---
import { getCurrentUser, loginUrl } from 'vite-wp/wordpress';
const user = await getCurrentUser();
const signIn = await loginUrl();
---
{user ? <p>Signed in as {user.displayName}</p> : <a href={signIn}>Sign in</a>}WooCommerce account/session helpers use the same invisible request context:
---
import { getCart, getCurrentCustomer } from 'vite-wp/woocommerce';
const customer = await getCurrentCustomer();
const cart = await getCart();
---For maximum plugin/payment compatibility, /my-account, /cart, and /checkout are WordPress-owned routes by default. Override wordpress.routes.wordpress in vitewp.config.ts when you are ready to render one of those paths in Astro.
For a a fully integrated experience vitewp supports authentication via the built in API, without exposing a public auth endpoint, see example:
import { requestPasswordReset, resetPassword, signInWithPassword, signOut } from 'vite-wp/wordpress';
await signInWithPassword({ email: 'editor@example.com', password: 'secret', remember: true });
await signOut();
await requestPasswordReset({ email: 'editor@example.com' });
await resetPassword({ login: 'editor@example.com', key: 'reset-key-from-email', password: 'new-secret' });