Skip to content
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

Unable to signup #1

Open
mbnoimi opened this issue Jan 29, 2021 · 10 comments
Open

Unable to signup #1

mbnoimi opened this issue Jan 29, 2021 · 10 comments

Comments

@mbnoimi
Copy link

mbnoimi commented Jan 29, 2021

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
Copy link
Owner

dhmlau commented Jan 31, 2021

@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
Copy link
Owner

dhmlau commented Jan 31, 2021

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
Copy link
Author

mbnoimi commented Jan 31, 2021

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
Copy link
Owner

dhmlau commented Feb 1, 2021

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

@mbnoimi
Copy link
Author

mbnoimi commented Feb 1, 2021

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
$
  1. Modified pds.datasource.ts for the proper config
  2. Created a new PostgreSQL database called testdb
  3. Run npm run rebuild
  4. Run npm run migrate
  5. Run npm start
  6. 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
Copy link
Author

mbnoimi commented Feb 1, 2021

IMPORTANT:
Step #5 only generates todo table

@dhmlau
Copy link
Owner

dhmlau commented Feb 1, 2021

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
Copy link
Author

mbnoimi commented Feb 2, 2021

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
Copy link
Owner

dhmlau commented Feb 3, 2021

@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
Copy link
Author

mbnoimi commented Feb 3, 2021

@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
$
  1. Modified pds.datasource.ts for the proper config
  2. Created a new PostgreSQL database called testdb
  3. Run npm run build
  4. Run npm run migrate (generated two tables)
    image
  5. Run npm start
  6. 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
$

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

No branches or pull requests

2 participants