sourcefuse / loopback4-starter

Loopback 4 starter application. Multi-tenant architecture supported. Authentication, Authorization, Soft deletes, environment vars, Audit logs, included.
MIT License
158 stars 59 forks source link

login auth/login #54

Closed personwholearn closed 4 years ago

personwholearn commented 4 years ago

when I go to http://127.0.0.1:3000/auth/login and send the request with the below

{ "client_id": "webapp", "client_secret": "saqw21!@", "username": "super_admin", "password": "test123!@#" }

I got reponed of

{ "error": { "statusCode": 401, "name": "UnauthorizedError", "message": { "name": "error", "length": 185, "severity": "ERROR", "code": "42P01", "position": "194", "file": "d:\pginstaller_12.auto\postgres.windows-x64\src\backend\parser\parse_relation.c", "line": "1173", "routine": "parserOpenTable" } } }

mayank-SFIN571 commented 4 years ago

Hi @personwholearn Can you share the .env file and the database structure. I just want to confirm whether the setup for the application is complete.

I am asking this because the error you are facing is when some table that you are trying to query to is not present in the database.

For reference you can check this

personwholearn commented 4 years ago

hi @mayank-SFIN571 ,this my .env file details : NODE_ENV= LOG_LEVEL= DB_HOST=localhost DB_PORT=5432 DB_USER=postgres DB_PASSWORD=123 DB_DATABASE=postgres DB_SCHEMA=postgres REDIS_HOST= REDIS_PORT= REDIS_URL= REDIS_PASSWORD= REDIS_DATABASE=0 JWT_SECRET= JWT_ISSUER= AUDIT_SCHEMA= USER_TEMP_PASSWORD= GOOGLE_AUTH_URL= GOOGLE_AUTH_CLIENT_ID= GOOGLE_AUTH_CLIENT_SECRET= GOOGLE_AUTH_TOKEN_URL= GOOGLE_AUTH_CALLBACK_URL=

personwholearn commented 4 years ago

in some other test project

DB_HOST=localhost DB_PORT=5432 DB_USER=postgres DB_PASSWORD=123 DB_DATABASE=todolist3 DB_SCHEMA=todolist3 REDIS_HOST=localhost REDIS_PORT=6379 REDIS_URL= REDIS_PASSWORD= REDIS_DATABASE=0 then i do db-migrate up

personwholearn commented 4 years ago

hello @mayank-SFIN571 , can you help me ?

mayank-SFIN571 commented 4 years ago

hello @personwholearn Totally missed the email for this thread.

Can you check whether your migrations were successful or not. The only reason I am focusing on the Database structure is because the error is for "tableName does not exist" according to the postgresql docs.

Also to ensure everything is in place, i cloned the repo and tried with this .env

NODE_ENV=production LOG_LEVEL=info DB_HOST=localhost DB_PORT=5432 DB_USER=postgres DB_PASSWORD=postgrestest DB_DATABASE=lbstarter DB_SCHEMA= REDIS_HOST=localhost REDIS_PORT=6379 REDIS_URL= REDIS_PASSWORD= REDIS_DATABASE=0 JWT_SECRET=plmnkoxswqaz JWT_ISSUER=lb_api AUDIT_SCHEMA=logs USER_TEMP_PASSWORD=temp123!@# DEFAULT_ROLE=super_admin

This configuration is working fine for me.

Also do check whether your Database structure look like this

image

In your case the name of the Database should be postgres and the schema name should again be postgres

mayank-SFIN571 commented 4 years ago

@personwholearn A wild guess, In migrations the schema that holds the user information is configured to be lbstarter (unless you modify the migrations), so keeping DB_SCHEMA=postgres will tell juggler to connect to schema postgres. But in actual scenario the schema is lbstarter. Please make sure we are having the right schema in the environment.

personwholearn commented 4 years ago

i will test your .env and give you feedback>>>

NODE_ENV=production LOG_LEVEL=info DB_HOST=localhost DB_PORT=5432 DB_USER=postgres DB_PASSWORD=postgrestest DB_DATABASE=lbstarter DB_SCHEMA= REDIS_HOST=localhost REDIS_PORT=6379 REDIS_URL= REDIS_PASSWORD= REDIS_DATABASE=0 JWT_SECRET=plmnkoxswqaz JWT_ISSUER=lb_api AUDIT_SCHEMA=logs USER_TEMP_PASSWORD=temp123!@# DEFAULT_ROLE=super_admin

@mayank-SFIN571

mayank-SFIN571 commented 4 years ago

@personwholearn just make sure you have the correct schema name in you .env file.

personwholearn commented 4 years ago

i will test it with schema of lbstarter and without schema

personwholearn commented 4 years ago

thanks bro so much it works

NODE_ENV=production LOG_LEVEL=info DB_HOST=localhost DB_PORT=5432 DB_USER=postgres DB_PASSWORD=123 DB_DATABASE=lbstarter DB_SCHEMA=lbstarter REDIS_HOST=localhost REDIS_PORT=6379 REDIS_URL= REDIS_PASSWORD= REDIS_DATABASE=0 JWT_SECRET=plmnkoxswqaz JWT_ISSUER=lb_api AUDIT_SCHEMA=logs USER_TEMP_PASSWORD=temp123!@# DEFAULT_ROLE=super_admin

@mayank-SFIN571 what is different between /auth/token and /auth/login-token and how can i login through postman or saving the access token for every requeset?

mayank-SFIN571 commented 4 years ago

Hi @personwholearn auth/token is actually a part of oauth. To correctly understand it please refer to this tutorial.

Whereas /auth/login-token is a Resource owner technique, which is again explained in the above mention tutorial.

You can work with any of the above methods, according to your application needs.

personwholearn commented 4 years ago

ok thanks soooooo much i also followed https://stackoverflow.com/questions/55524597/loopback-4-add-authorize-button-in-api-explorer

for Adding 'Authorize' button in API explorer and it works .

personwholearn commented 4 years ago

@mayank-SFIN571 can I change the password of "temp123!@#" of the new user through API

personwholearn commented 4 years ago

@mayank-SFIN571 which controller can I change the password ? or do I have to create a new one?