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
/Users/redactedusername/Desktop/Projects/Portfolio/books-api/node_modules/@redwoodjs/api/dist/functions/dbAuth/DbAuthHandler.js:538:42
535 } = this.params;
536
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?
@rob I did. I can see the table in my DB, and here’s the migration.sql file it generated
-- CreateTable
CREATE TABLE "User" (
"id" SERIAL NOT NULL,
"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");
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?
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)
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
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?
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…
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.