-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
how we can add login method in usercontroller class in loopback4 API? needs more clarification on this #5407
Comments
Please find a working example below: @post('/users/login', {
responses: {
'200': {
description: 'Token',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
token: {
type: 'string',
},
},
},
},
},
},
},
})
async login(
@requestBody(CredentialsRequestBody) credentials: Credentials,
): Promise<{token: string}> {
// ensure the user exists, and the password is correct
const user = await this.userService.verifyCredentials(credentials);
// convert a User object into a UserProfile object (reduced set of properties)
const userProfile = this.userService.convertToUserProfile(user);
// create a JSON Web Token based on the user profile
const token = await this.jwtService.generateToken(userProfile);
return {token};
}
} From example shopping. Hope that helps. Please explain what is confusing and we'll see what can be done to improve docs. |
yes, i have tried this...but i am getting errors. Error is like:- Property 'userService' does not exist on type 'UserController'. |
@kanusoni Please take a closer look at the Shopping example and follow the breadcrumbs (look at Constructor that instantiates services and follow the imports to find their implementation. It takes time to familiarise yourself but it is worth it if the tutorial does not suit you. |
@kanusoni, we recently published an extension called While learning how to use this extension, I created this blog: https://medium.com/@MobileDiana/add-jwt-authentication-in-your-loopback-4-application-325137642c2c. Hope this helps. |
@dhmlau Thanks Diana for you reply. |
@dhmlau can you help me out in the below issue:- because of this issue JWT token is also not generating. |
@kanusoni please provide a sample project or sandbox to check your code |
+1. From the error in the screen shot, it seems like the |
… On Fri, May 15, 2020 at 5:28 AM Diana Lau ***@***.***> wrote:
@kanusoni <https://github.com/kanusoni> please provide a sample project
or sandbox to check your code
+1. From the error in the screen shot, it seems like the password was not
specified. If it was specified and still got this error, it's the best if
you can share your app. Thanks.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5407 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/APSACQH3LNNDATC3TP6QOLDRRSASDANCNFSM4M7OK7VQ>
.
|
@deepakrkris @dhmlau sent App to you. please check the code and let me know the solution. |
@dougal83 shared the code in github repo. |
@kanusoni I'm a little unsure how you've arrived at your implementation, it seems a little confused. Are you following a particular tutorial? It may be worth starting afresh following the tutorial mentioned above by Diana or use Shopping Example as a reference to patch up your current project and methodically inspecting models/controllers at this point. That being said there are several issues:
schema: getModelSchemaRef(NewUserRequest, {
title: 'NewUser',
exclude: ['id','role']
}), I would highly recommend using the Shopping Example as a reference to patch up your work further. Good luck. Hope that helps a bit. |
@dougal83 i am following this Shopping example tutorial only. |
@dhmlau any update from your side on the code which i sent to you? |
@kanusoni I had a quick look of your repo, seems you don't secure any of your endpoints with FYI - #5463 is the latest working example that demos JWT AUTH only. The shopping example shows a more complicated scenario so it has noisy code for other stuff. And that example's corresponding tutorial doc #5421. Let me know if the latest example and tutorial still confuse you. |
@HrithikMittal thanks! I think this issue is more like a question, and I think my comment above #5407 (comment) points out the problem and provides a much easier tutorial to begin with authentication. I am closing it. Feel free to reopen the issue if you still have problem :) |
src/controllers/ctr-users.controller.ts:75:18 - error TS2345: Argument of type '{ description: string; required: boolean; content: { 'application/json': { schema: { type: string; required: string[]; properties: { login: { type: string; }; password: { type: string; minLength: number; }; }; }; }; }; }' is not assignable to parameter of type 'Partial'. 75 @requestBody(CredentialsRequestBody) credentials: Credentials, How to solve this error ?? |
@Arathy-sivan Please ask in the Slack channel, StackOverflow with #loopback4 tag, or open a new GitHub issue. That way, it would be easier to discover and respond. |
Hello,
I have created User controller in loopback4 Explorer but i need login method for JWT authentication.
Whatever is written in loopback.io tutorial is bit confusing so do you have any other tutorial for the clarification.
The text was updated successfully, but these errors were encountered: