Skip to content

Failing to signup when running app locally #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
chrisg220 opened this issue Oct 19, 2024 · 7 comments
Closed

Failing to signup when running app locally #450

chrisg220 opened this issue Oct 19, 2024 · 7 comments

Comments

@chrisg220
Copy link

I am seeking help debugging my authentication error for the ai-chatbot template app so that I can login and play with the example chatbot application. However, I'm failing to even create a user via the UI login page.

I followed every step of the README. I renamed .env.example to .env.local and inserted my private keys for OPENAI_API_KEY, AUTH_SECRET, BLOB_READ_WRITE_TOKEN, and POSTGRES_URL. I have the app running locally on localhost:3000. I am trying to sign up by filling in an email address and password. But when I press sign up, I get the following errors in the console.

// console output

pnpm dev

> ai-chatbot@0.1.0 dev /Users/christophergonzales/Projects/ai-chatbot
> next dev --turbo

  ▲ Next.js 15.0.0-canary.152 (turbo)
  - Local:        http://localhost:3000
  - Environments: .env.local

 ✓ Starting...
 ✓ Compiled in 271ms
 ✓ Ready in 990ms
 ○ Compiling /register ...
 ✓ Compiled /register in 2.5s
 GET /register 200 in 2776ms
Failed to get user from database
 POST /register 200 in 260ms
Screenshot 2024-10-18 at 6 02 21 PM
@chrisg220
Copy link
Author

I got this to work by manually migrating and building (shown below), and then re-starting the app.

tsx db/migrate && next build

I believe I followed all the steps correctly in the README, so I expected it to work when I started the app. I just wanted to follow up with my resolution in case:

  1. this is a "missing step" in the README
  2. I actually did something out of order, and anyone else who does can learn how to resolve a similar issue for them.

@zdvman
Copy link

zdvman commented Oct 21, 2024

Hi, did you solve the issue? I have the same problem.

@chrisg220
Copy link
Author

@zdvman Yes my problem was solved. Did you have the same error as me? And did you try running the commands I wrote above? What are you seeing now?

@zdvman
Copy link

zdvman commented Oct 22, 2024

@zdvman Yes my problem was solved. Did you have the same error as me? And did you try running the commands I wrote above? What are you seeing now?

Yes, I used this command and now it works. On my opinion one step of installation in description of this template is missing. Thanks.

@huyouare
Copy link

huyouare commented Nov 2, 2024

I'm also able to repro this issue upon initial installation.
Screenshot 2024-11-02 at 1 47 19 PM

@sudheer-salavadi
Copy link

sudheer-salavadi commented Mar 6, 2025

🚨 Issue: “Failed to Create Account” During Signup

🔹 Cause:
• The app requires a PostgreSQL database, but many of us didn't realize this.
• Without a database, user authentication and storage don’t work, leading to this error.

✅ Solution: Install and Set Up PostgreSQL

  1. After installing PostgresSQL Open Terminal and connect psql -U postgres (Use postgres as the default superuser.)
  2. Initiate your PostgreSQL and create data base e.g. CREATE DATABASE yourapp_db;
  3. verify it was created \l
  4. Exit PostgreSQL: \q
  5. Now Edit .env.local inside your Next.js project and add: POSTGRES_URL=postgres://postgres@localhost:5432/yourapp_db

Next
The database is now created but its empty. So run migrations
pnpm tsx lib/db/migrate.ts && pnpm run build

Then check if tables were created.
psql -U postgres -d yourapp_db

then \dt

If the database is setup correctly you should see the following tables

public | User       | table | postgres
public | Chat       | table | postgres
public | Message    | table | postgres

Note: If no tables appear, migrations did not run properly.

That's it, if you spot user table, you are good to go. Run your NextJS app, try signing up. It should work.

Image

Your .env.local file should look something like the following

# Supabase configuration (optional)
NEXT_PUBLIC_SUPABASE_URL=****
SUPABASE_SERVICE_ROLE_KEY=****

# Authentication (required for the template). Get it by visiting https://generate-secret.vercel.app/32
AUTH_SECRET=****

# AI Provider (Anthropic Claude or OpenAI)
ANTHROPIC_API_KEY=your_anthropic_api_key

# or
OPENAI_API_KEY=your_openai_api_key

POSTGRES_URL=postgres://postgres@localhost:5432/yourapp_db or POSTGRES_URL=postgres://yourname@localhost:5432/yourapp_db

@karlhorky
Copy link

@sudheer-salavadi nice alternative! I've opened a PR to document setup and usage of local PostgreSQL and .env.local files here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants