Skip to content

Commit

Permalink
添加配置参数说明
Browse files Browse the repository at this point in the history
  • Loading branch information
lccf committed Jun 9, 2024
1 parent bec4ca7 commit c27754b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions docs/learn/security-db-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ export function sha256Encode(content: string) {
创建`src/backend/authentication/password-encoder.ts`文件处理密码比较,内容如下:

```ts
import { Service } from '@malagu/core';
import { PasswordEncoder } from '@malagu/security/lib/node';
import { sha256Encode } from '../utils/crypto';
import { Service } from "@malagu/core";
import { PasswordEncoder } from "@malagu/security/lib/node";
import { sha256Encode } from "../utils/crypto";
@Service({ id: PasswordEncoder, rebind: true })
export class PasswordEncoderImpl implements PasswordEncoder {
Expand Down
11 changes: 10 additions & 1 deletion docs/learn/security-jwt.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ lang: zh-CN
yarn add @malagu/jwt
```

修改 malagu.yml 添加 jwt 密钥配置

```yml
malagu:
# 新增内容
jwt:
secret: abcdefg
```
### 登录和认证
创建`src/backend/authentication/authentication-success-handler.ts`文件,登录成功时返回 token ,内容如下:
Expand All @@ -30,7 +39,7 @@ export class AuthenticationSuccessHandlerImpl implements AuthenticationSuccessHa
async onAuthenticationSuccess(authentication: Authentication): Promise<void> {
const response = Context.getResponse();
let token = await this.jwtService.sign(authentication.name);
let token = await this.jwtService.sign({ username: authentication.name });
response.body = JSON.stringify({ token });
}
}
Expand Down

0 comments on commit c27754b

Please sign in to comment.