--- title: Use Neon Auth with React (API methods) subtitle: Build your own auth UI enableTableOfContents: true updatedOn: '2025-11-12T00:00:00.000Z' layout: wide --- If you don't have a Neon project yet, create one at [console.neon.tech](https://console.neon.tech). Go to the **Auth** page in your project dashboard and click **Enable Auth**. You can then find your Auth **Base URL** on the Configuration tab. Copy this URL - you'll need it in the next step. ![Neon Auth Base URL](/docs/auth/neon-auth-base-url.png) Create a React app using Vite. ```bash npm create vite@latest my-app -- --template react ``` The Neon SDK provides authentication methods like `signUp()`, `getSession()`, and `signOut()` for your React app. ```bash cd my-app npm install @neondatabase/neon-js ``` Create a `.env` file in your project root and add your Auth Base URL: Replace the URL with your actual Auth Base URL from the Neon Console. ```bash VITE_NEON_AUTH_URL=https://ep-xxx.neonauth.us-east-2.aws.neon.build/neondb/auth ``` Create a `src/auth.js` file to configure your auth client: ```javascript import { createAuthClient } from '@neondatabase/neon-js/auth'; export const authClient = createAuthClient(import.meta.env.VITE_NEON_AUTH_URL); ``` Neon JS uses a programmatic approach for managing auth state. You'll use React hooks like `useEffect` to check the session and handle auth changes. Replace the contents of `src/App.jsx` with the following code to implement [sign-up](/docs/reference/javascript-sdk#auth-signup), [sign-in](/docs/reference/javascript-sdk#auth-signinwithpassword), and [sign-out](/docs/reference/javascript-sdk#auth-signout): ```jsx import { useState, useEffect } from 'react'; import { authClient } from './auth'; import './App.css'; export default function App() { const [session, setSession] = useState(null); const [user, setUser] = useState(null); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [isSignUp, setIsSignUp] = useState(true); const [loading, setLoading] = useState(true); useEffect(() => { authClient.getSession().then((result) => { if (result.data?.session && result.data?.user) { setSession(result.data.session); setUser(result.data.user); } setLoading(false); }); }, []); const handleSubmit = async (e) => { e.preventDefault(); const result = isSignUp ? await authClient.signUp.email({ name: email.split('@')[0] || 'User', email, password }) : await authClient.signIn.email({ email, password }); if (result.error) { alert(result.error.message); return; } const sessionResult = await authClient.getSession(); if (sessionResult.data?.session && sessionResult.data?.user) { setSession(sessionResult.data.session); setUser(sessionResult.data.user); } }; const handleSignOut = async () => { await authClient.signOut(); setSession(null); setUser(null); }; if (loading) return
Loading...
; if (session && user) { return (

Logged in as {user.email}

); } return (

{isSignUp ? 'Sign Up' : 'Sign In'}

setEmail(e.target.value)} required /> setPassword(e.target.value)} required />

{isSignUp ? ( <> Already have an account?{' '} { e.preventDefault(); setIsSignUp(false); }} > Sign in ) : ( <> Don't have an account?{' '} { e.preventDefault(); setIsSignUp(true); }} > Sign up )}

); } ```
Start the development server: Open your browser to `http://localhost:5173` and create a test user. ```bash npm run dev ``` As users sign up, their profiles are synced to your Neon database in the `neon_auth.user` table. Query your users table in the SQL Editor to see your new users: ```sql SELECT * FROM neon_auth.user; ```
## Next steps - [Learn about Neon Auth concepts](/docs/auth/overview) - [Explore the Neon Data API](/docs/data-api/get-started) to build a REST API for your data - [View complete SDK reference](/docs/reference/javascript-sdk)