dbAuth signup failure

I’m going through the Getting Started docs to set up dbAuth, but I’m running into a problem when I go to sign up as a user.

I ran yarn rw setup auth dbAuth and that worked, then I set up a user model and migrated it successfully (I can see the table in my db). Here’s my model:

model User {
  id Int @id @default(autoincrement())
  name  String?
  email String @unique
  hashedPassword  String
  salt String
  resetToken  String?
  resetTokenExpiresAt DateTime?

I then ran the dbAuth generator w/ yarn rw g dbAuth and got my login/signup pages.

The problem happens when I try to sign up. I enter an email and password on the /signup page, and a Toast message with this error pops up:

Invalid `this.dbAccessor.findUnique()` invocation in

   535 } = this.params;
   537 if (this._validateField('username', username) && this._validateField('password', password)) {
→  538   const user = await this.dbAccessor.findUnique(
  Failed to validate the query: `Field does not exist on enclosing type.` at `Query.findUniqueUser`

This message looks familiar from this thread, but that fix doesn’t work. I tried stopping my dev and running yarn rw g types, but that didn’t work. I also tried generating an .sdl file for my User model and generating the types after that, but that doesn’t fix the problem either.

Given the error message, my hunch is that the problem is related to TS types, but I’m not sure. Any ideas how to fix this?

Have you run yarn rw prisma migrate dev to create the new User database table?

@rob I did. I can see the table in my DB, and here’s the migration.sql file it generated

-- CreateTable
    "name" TEXT,
    "email" TEXT NOT NULL,
    "hashedPassword" TEXT NOT NULL,
    "salt" TEXT NOT NULL,
    "resetToken" TEXT,
    "resetTokenExpiresAt" TIMESTAMP(3),

    CONSTRAINT "User_pkey" PRIMARY KEY ("id")

-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");

Hmm, if you run yarn rw build does it complete or error out?

Not only did the build complete, but now I’m able to register and log in even though I’m running on dev? Not sure if I overlooked something when I was troubleshooting or if yarn rw build actually fixed the problem somehow.

When you run build it does compile the app into the dist directories in web and api, but when you run yarn rw dev it still starts from scratch like normal, it doesn’t care about dist.

Maybe there was something weird with the types in there and build fixed them! If you look in the .redwood dir there’s a bunch of secret stuff there that we use internally to activate a bunch of functionality. Redwood’s usually really good about keeping that all up to date whenever you modify and save files but maybe something got stuck?

Glad you’re back up and running!

1 Like

@rob I am having a very similar issue. I went through the entire dbAuth setup and it worked fine.

Then I tried to add a name attribute to the User and now I think my graphql server is not spinning up correctly.

Steps I’ve done so far:

  • updated the prisma.schema with the new attribute.
  • ran yarn rw prisma migrate dev and created the migration
  • added name: userAttributes.name, to the db.user.create in the signUp handler in api/src/functions/auth.ts
  • added name field to the sign up form
  • ran yarn rw g types
  • ran yarn rw build just in case

After all of that when running yarn rw dev i am getting:

yarn rw dev
gen | Generating TypeScript definitions and GraphQL schemas...
gen | 19 files generated
web | assets by path static/js/*.js 4.48 MiB
web |   asset static/js/app.bundle.js 3 MiB [emitted] (name: app) 1 related asset
web |   asset static/js/src_pages_ResetPasswordPage_ResetPasswordPage_tsx.chunk.js 404 KiB [emitted] 1 related asset
web |   asset static/js/src_pages_SignupPage_SignupPage_tsx.chunk.js 380 KiB [emitted] 1 related asset
web |   asset static/js/src_pages_LoginPage_LoginPage_tsx.chunk.js 380 KiB [emitted] 1 related asset
web |   asset static/js/src_pages_ForgotPasswordPage_ForgotPasswordPage_tsx.chunk.js 297 KiB [emitted] 1 related asset
web |   asset static/js/runtime-app.bundle.js 50.4 KiB [emitted] (name: runtime-app) 1 related asset
web |   asset static/js/src_pages_HomePage_HomePage_tsx.chunk.js 4.19 KiB [emitted] 1 related asset
web |   asset static/js/src_pages_NotFoundPage_NotFoundPage_tsx.chunk.js 3.38 KiB [emitted] 1 related asset
web | asset README.md 1.9 KiB [emitted] [from: public/README.md] [copied]
web | asset favicon.png 1.7 KiB [emitted] [from: public/favicon.png] [copied]
web | asset index.html 483 bytes [emitted]
web | asset robots.txt 24 bytes [emitted] [from: public/robots.txt] [copied]
web | Entrypoint app 3.05 MiB (2.98 MiB) = static/js/runtime-app.bundle.js 50.4 KiB static/js/app.bundle.js 3 MiB 2 auxiliary assets
web | orphan modules 1.25 MiB [orphan] 559 modules
web | runtime modules 34 KiB 18 modules
web | modules by path ../node_modules/ 2.7 MiB 886 modules
web | modules by path ./src/ 64.7 KiB
web |   modules by path ./src/pages/ 37.6 KiB
web |     ./src/pages/FatalErrorPage/FatalErrorPage.tsx 3.11 KiB [built] [code generated]
web |     ./src/pages/ForgotPasswordPage/ForgotPasswordPage.tsx 5.31 KiB [built] [code generated]
web |     + 5 modules
web |   modules by path ./src/*.css 22.2 KiB
web |     ./src/scaffold.css 2.39 KiB [built] [code generated]
web |     ./src/index.css 2.38 KiB [built] [code generated]
web |     + 2 modules
web |   modules by path ./src/*.tsx 4.86 KiB
web |     ./src/App.tsx 1.84 KiB [built] [code generated]
web |     ./src/Routes.tsx 3.02 KiB [built] [code generated]
web | webpack 5.70.0 compiled successfully in 2495 ms
web | <e> [webpack-dev-server] [HPM] Error occurred while proxying request localhost:8910/auth?method=getToken to http://[::1]:8911/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
web | <e> [webpack-dev-server] [HPM] Error occurred while proxying request localhost:8910/auth?method=getToken to http://[::1]:8911/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)

Do you have any clue of whay might have going on here? or what can I try? am I missing something?

Huh…you’re coming at it from a completely different angle, but check THIS out: Tutorial Issue : Error occurred while proxying request localhost:8910/graphql to http://[::1]:8911/

Did you upgrade to v1.0 before adding User.name? I wonder if something included in 1.0 is just causing this weird proxy issue to the API server…

I did upgrade, and I was just seeing that. I know I have ipv6 disabled cause it was causing some issues when installing rails gems with bundler for work.

I did what the thread suggested: RWJS_DEV_API_URL="http://localhost" yarn rw dev

but now I am getting:

web | <e> [webpack-dev-server] [HPM] Error occurred while proxying request localhost:8910/auth?method=getToken to http://localhost:8911/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)

Connection refused? What the heck is going on… can you get to http://localhost:8911/graphql in a browser?

nope it fails to load

That sounds like the API server isn’t running at all…try doing a yarn rw build, and if that works try yarn rw serve to serve it in production mode and see if that does anything different.

with yarn rw serve it works perfect but I took it down and ran again with yarn rw dev and RWJS_DEV_API_URL=“http://localhost” yarn rw dev as well and both fail again with the same error

don’t know if it helps but with the changes in this commit is when it starts breaking in dev mode add name to user · aguscha333/jarvis@559e56a · GitHub

Is there a previous commit to that where you upgraded to v1.0? If you roll back to before that, then apply these schema changes, wonder if it still happens?

No, I created the project from scratch a few hours ago from v1 directly

Interestingggg What if you leave the database changes in place, but remove the changes to auth.js? That’s the only thing that should be affecting to the API server… this is warping my mind, I don’t see how adding those fields would have anything to do with the web side trying to send a request to the IPv6 endpoint like people are complaining about in that other thread…

same error

I’m running out of ideas here. Might be time to call in backup! @dthyresson any idea what’s going on and if it’s related to that other thread? I gotta think these are related, it’s such a weird, specific error.

Some context about rw dev: It tries to start up api and web side in parallel, but sometimes when api side takes a little bit longer than the web to start then the web (which is trying to proxy the apiUrl) prints these in logs.
Or if there’s some error while starting the api server but it would have printed the error, which is not the case here.

But if there’s no log saying api server running after proxy error logs then something is definitely up. @aguscha333 Can you try to access localhost:8910/.redwood/functions/graphql after running yarn rw dev? It should show GraphQL if everything worked.