MCPcopy
hub / github.com/tsedio/tsed / LoginLocalProtocol

Class LoginLocalProtocol

docs/tutorials/snippets/passport/LoginLocalProtocol.ts:18–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16 }
17})
18export class LoginLocalProtocol implements OnVerify, OnInstall, BeforeInstall {
19 @Inject()
20 private usersService: UsersService;
21
22 // hook added with v6.99.0
23 async $beforeInstall(settings: IStrategyOptions): Promise<IStrategyOptions> {
24 // load something from backend
25 // settings.usernameField = await this.usersService.loadFieldConfiguration()
26
27 return settings;
28 }
29
30 $onInstall(strategy: Strategy): void {
31 // intercept the strategy instance to adding extra configuration
32 }
33
34 async $onVerify(@Req() request: Req, @BodyParams() credentials: Credentials) {
35 const {email, password} = credentials;
36
37 const user = await this.usersService.findOne({email});
38
39 if (!user) {
40 return false;
41 // OR throw new PassportMessage("Wrong credentials")
42 }
43
44 if (!user.verifyPassword(password)) {
45 return false;
46 // OR throw new PassportMessage("Wrong credentials")
47 }
48
49 return user;
50 }
51}

Callers

nothing calls this directly

Calls 1

InjectFunction · 0.90

Tested by

no test coverage detected