diff --git a/README.md b/README.md index ad437cf..f8be39e 100644 --- a/README.md +++ b/README.md @@ -61,32 +61,29 @@ Download and run the interactive installer from the [Official PostgreSQL Downloa ``` *(On macOS/Windows, open your terminal/command prompt and run `psql postgres` or use a graphical tool like PgAdmin).* -2. Create a new database named `brew`: - ```sql - CREATE DATABASE brew; - ``` - -3. Create a database user with a secure password: +2. Create a database user with a secure password: ```sql CREATE USER brew_user WITH PASSWORD 'your_secure_password'; ``` -4. Grant all privileges on the database to your new user: +3. Create the database and set its owner to `brew_user`. Setting the owner guarantees that the user has full table creation privileges on the default `public` schema: ```sql - GRANT ALL PRIVILEGES ON DATABASE brew TO brew_user; + CREATE DATABASE brew OWNER brew_user; ``` -5. (For PostgreSQL 15+) Connect to the database and grant schema permissions: - ```sql - \c brew - GRANT ALL ON SCHEMA public TO brew_user; - ``` - -6. Exit the PostgreSQL shell: +4. Exit the PostgreSQL shell: ```sql \q ``` +> [!TIP] +> **Troubleshooting "Permission denied for schema public" (PostgreSQL 15+):** +> If you already created the database without setting `brew_user` as the owner and encounter this error, log in as the superuser (`postgres`), connect to the `brew` database, and explicitly grant the schema privileges: +> ```sql +> \c brew +> GRANT ALL ON SCHEMA public TO brew_user; +> ``` + > [!NOTE] > Database tables (such as `users`) are initialized automatically when you start the backend server, as defined in [server/db.js](file:///home/sortedcord/Projects/brew/server/db.js). diff --git a/src/AuthContext.jsx b/src/AuthContext.jsx index 0a05bec..69d1288 100644 --- a/src/AuthContext.jsx +++ b/src/AuthContext.jsx @@ -9,7 +9,7 @@ export function AuthProvider({ children }) { const verifyToken = useCallback(async (tkn) => { try { - const res = await fetch('http://localhost:5000/api/verify-token', { + const res = await fetch('/api/verify-token', { headers: { 'Authorization': `Bearer ${tkn}` } }); if (res.ok) { @@ -42,7 +42,7 @@ export function AuthProvider({ children }) { const login = async (email, password) => { try { - const res = await fetch('http://localhost:5000/api/login', { + const res = await fetch('/api/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, password }) @@ -61,7 +61,7 @@ export function AuthProvider({ children }) { const register = async (username, email, password) => { try { - const res = await fetch('http://localhost:5000/api/register', { + const res = await fetch('/api/register', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username, email, password }) diff --git a/vite.config.js b/vite.config.js index 8b0f57b..f61a064 100644 --- a/vite.config.js +++ b/vite.config.js @@ -4,4 +4,12 @@ import react from '@vitejs/plugin-react' // https://vite.dev/config/ export default defineConfig({ plugins: [react()], + server: { + proxy: { + '/api': { + target: 'http://localhost:5000', + changeOrigin: true, + } + } + } })