dhmlau / loopback4-example-todo-jwt-db

Other
1 stars 0 forks source link

Unable to signup #1

Open mbnoimi opened 3 years ago

mbnoimi commented 3 years ago

Hello,

Whenever I try to call /signup I get the following error message:

Server is running at http://[::1]:3000
WARNING: relational database doesn't support {strict: false} mode. {strict: true} mode will be set for model User instead.
Request POST /signup failed with status code 500. TypeError: this.userRepository.userCredentials is not a function
    at UserController.signUp (/home/laptop/loopback4-example-todo-jwt-db/dist/controllers/user.controller.js:73:35)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async /home/laptop/loopback4-example-todo-jwt-db/node_modules/@loopback/rest/dist/providers/invoke-method.provider.js:37:32
    at async /home/laptop/loopback4-example-todo-jwt-db/node_modules/@loopback/express/dist/middleware-interceptor.js:82:25
    at async /home/laptop/loopback4-example-todo-jwt-db/node_modules/@loopback/express/dist/middleware-interceptor.js:82:25
    at async /home/laptop/loopback4-example-todo-jwt-db/node_modules/@loopback/rest/dist/providers/send.provider.js:39:32
    at async MySequence.handle (/home/laptop/loopback4-example-todo-jwt-db/node_modules/@loopback/rest/dist/sequence.js:201:9)
    at async HttpHandler._handleRequest (/home/laptop/loopback4-example-todo-jwt-db/node_modules/@loopback/rest/dist/http-handler.js:64:9)
^C
$
dhmlau commented 3 years ago

@mbnoimi, I realized that I couldn't simply create the repository using lb4 repository command, because the User model has a hasOne relationship with UserCredentials. I deleted the User and UserCredentials models and repository classes (and make sure you update the index.ts files). And it's working fine.

Trying to remember what I was doing when writing the tutorial... I think I probably just copied the user models for the database migration script to run.

dhmlau commented 3 years ago

It should be working after you deleted the model and repository files.


testdb=# select * from public.user;
                  id                  | realm | username |       email        | emailverified | verificationtoken 
--------------------------------------+-------+----------+--------------------+---------------+-------------------
 5cf29c80-b2c3-4b17-bef7-4dd76021bcd5 |       |          | testuser1@test.com |               | 
(1 row)

testdb=# select * from public.usercredentials;
                  id                  |                           password                           |                userid            

--------------------------------------+--------------------------------------------------------------+----------------------------------
----
 a9e80afb-f251-479c-8a86-1c91e2bbe373 | $2a$10$am49HadqPQXKboXpZ9QQre79VFoftYGOSX0DzC5gW76djjWfudfIy | 5cf29c80-b2c3-4b17-bef7-4dd76021b
cd5
(1 row)
mbnoimi commented 3 years ago

It should be working after you deleted the model and repository files.

Still doesn't work. May you please make a commit for the correction you've suggested!

dhmlau commented 3 years ago

I pushed my changes that produced this result in branch https://github.com/dhmlau/loopback4-example-todo-jwt-db/tree/delete-artifacts.

mbnoimi commented 3 years ago

I pushed my changes that produced this result in branch https://github.com/dhmlau/loopback4-example-todo-jwt-db/tree/delete-artifacts.

Still doesn't work! What I did:

  1. Checked out the new brunch:
    $ git name-rev --name-only HEAD
    remotes/origin/delete-artifacts
    $
  2. Modified pds.datasource.ts for the proper config
  3. Created a new PostgreSQL database called testdb
  4. Run npm run rebuild
  5. Run npm run migrate
  6. Run npm start
  7. Executed /signup then got this error: image
    Server is running at http://[::1]:3000
    WARNING: relational database doesn't support {strict: false} mode. {strict: true} mode will be set for model User instead.
    Request POST /signup failed with status code 500. error: relation "public.user" does not exist
    at Parser.parseErrorMessage (/home/laptop/loopback4-example-todo-jwt-db/node_modules/pg-protocol/dist/parser.js:278:15)
    at Parser.handlePacket (/home/laptop/loopback4-example-todo-jwt-db/node_modules/pg-protocol/dist/parser.js:126:29)
    at Parser.parse (/home/laptop/loopback4-example-todo-jwt-db/node_modules/pg-protocol/dist/parser.js:39:38)
    at Socket.<anonymous> (/home/laptop/loopback4-example-todo-jwt-db/node_modules/pg-protocol/dist/index.js:10:42)
    at Socket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
    at Socket.Readable.push (internal/streams/readable.js:223:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
    ^C
    $
mbnoimi commented 3 years ago

IMPORTANT: Step #5 only generates todo table

dhmlau commented 3 years ago

For step 4, can you run npm run build instead?

Step #5 only generates todo table

yes. from the error you've shown, it looks like user table doesn't exist.

mbnoimi commented 3 years ago

For step 4, can you run npm run build instead?

I did it to be sure there is no old files (from master brunch) will affect on the new build.

yes. from the error you've shown, it looks like user table doesn't exist.

May you modify the code to fix this issue?

dhmlau commented 3 years ago

@mbnoimi, I'm using the master branch to create the table. If you take my repo (master branch) and make it to connect to your database, were you able to create the table?

mbnoimi commented 3 years ago

@mbnoimi, I'm using the master branch to create the table. If you take my repo (master branch) and make it to connect to your database, were you able to create the table?

Still doesn't work! What I did:

  1. Checked out the new brunch:
    $ git name-rev --name-only HEAD
    master
    $
  2. Modified pds.datasource.ts for the proper config
  3. Created a new PostgreSQL database called testdb
  4. Run npm run build
  5. Run npm run migrate (generated two tables) image
  6. Run npm start
  7. Executed /signup then got this error: image
Server is running at http://[::1]:3000
WARNING: relational database doesn't support {strict: false} mode. {strict: true} mode will be set for model User instead.
Request POST /signup failed with status code 500. TypeError: this.userRepository.userCredentials is not a function
    at UserController.signUp (/home/laptop/loopback4-example-todo-jwt-db/dist/controllers/user.controller.js:73:35)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async /home/laptop/loopback4-example-todo-jwt-db/node_modules/@loopback/rest/dist/providers/invoke-method.provider.js:37:32
    at async /home/laptop/loopback4-example-todo-jwt-db/node_modules/@loopback/express/dist/middleware-interceptor.js:82:25
    at async /home/laptop/loopback4-example-todo-jwt-db/node_modules/@loopback/express/dist/middleware-interceptor.js:82:25
    at async /home/laptop/loopback4-example-todo-jwt-db/node_modules/@loopback/rest/dist/providers/send.provider.js:39:32
    at async MySequence.handle (/home/laptop/loopback4-example-todo-jwt-db/node_modules/@loopback/rest/dist/sequence.js:201:9)
    at async HttpHandler._handleRequest (/home/laptop/loopback4-example-todo-jwt-db/node_modules/@loopback/rest/dist/http-handler.js:64:9)
^C
$