Composables
useXAuth
High-level Neon Auth composable with loading states, toast notifications, and automatic navigation after auth events.
useXAuth
High-level authentication composable wrapping useXNeonAuth(). Adds loading state management, Nuxt UI toast notifications on error, and automatic navigation after login, signup, and logout. Use this composable for all standard auth flows in your app.
Usage
const {
user,
isLoading,
isAuthenticated,
emailSent,
codeSent,
checkAuth,
login,
signup,
logout,
forgotPassword,
resetPassword,
loginWithProvider,
sendOtp,
verifyOtp,
sendMagicLink,
handleMagicLinkCallback,
changePassword,
updateUser,
deleteAccount,
resetState,
authClient,
} = useXAuth()
Returns
| Key | Type | Description |
|---|---|---|
user | () => Promise<User | null> | Get the current authenticated user. |
isLoading | Ref<boolean> | true while any async auth operation is in progress. |
isAuthenticated | Ref<boolean> | Auth status — call checkAuth() first to populate. |
emailSent | Ref<boolean> | true after a magic link or forgot-password email is sent. |
codeSent | Ref<boolean> | true after an OTP code is sent. |
checkAuth() | Promise<User | null> | Checks auth status and updates isAuthenticated. |
login(email, password) | Promise<User | null> | Sign in with email and password. Shows toast on error, navigates to afterLogin on success. |
signup(email, password) | Promise<User | null> | Create a new account. Shows toast on error, navigates to afterSignup on success. |
logout() | Promise<boolean> | Sign out. Navigates to afterLogout on success. |
forgotPassword(email) | Promise<boolean> | Send a password reset email. Sets emailSent on success. |
resetPassword(code, password) | Promise<true | { error }> | Reset password using a token from the reset email. |
loginWithProvider(provider) | Promise<boolean> | Initiate OAuth sign-in with the given provider. |
sendOtp(email) | Promise<boolean> | Send an OTP verification code. Sets codeSent on success. |
verifyOtp(code) | Promise<User | null> | Verify an OTP code and sign in. |
sendMagicLink(email) | Promise<boolean> | Send a magic link email. Sets emailSent on success. |
handleMagicLinkCallback(token) | Promise<true | { error }> | Verify a magic link token from the callback URL. |
changePassword(current, new) | Promise<boolean> | Change password for an authenticated user. |
updateUser({ name?, image? }) | Promise<boolean> | Update the current user's profile. |
deleteAccount(password) | Promise<boolean> | Permanently delete the user's account. |
resetState() | void | Reset emailSent and codeSent to false. |
authClient | object | Direct access to the underlying Neon Auth client. |
AI Context
composable: useXAuth
package: "@xenterprises/nuxt-x-neon-auth"
use-when: >
Implementing any auth flow in a Nuxt app using nuxt-x-neon-auth. Covers
email/password login and signup, OAuth, OTP, magic links, password reset,
profile updates, and account deletion. Prefer this over useXNeonAuth() for
all standard UI flows — it handles loading states, toasts, and navigation
automatically. Call checkAuth() on mount or in middleware to populate
isAuthenticated.
