我正在尝试使用 NestJs 上的访问和刷新令牌进行身份验证。正如我在 Nestjs 文档中看到的那样,我应该在 auth 模块中注册我的密钥。我就是这么做的。
@Module({
imports: [
MongooseModule.forFeature([{ name: 'RefreshToken', schema: RefreshTokenSchema }]),
UsersModule,
PassportModule,
JwtModule.register({
secret: jwtConstants.secret,
}),
],
providers: [AuthService, LocalStrategy, JwtStrategy],
controllers: [AuthController],
})
export class AuthModule {}
Run Code Online (Sandbox Code Playgroud)
当我在身份验证服务中创建令牌时,将使用此密钥。
import { JwtService } from '@nestjs/jwt';
const accessToken = this.jwtService.sign(payload, { expiresIn: '60s'});
const refreshToken = this.jwtService.sign(payload, { expiresIn: '24h' });
Run Code Online (Sandbox Code Playgroud)
当我尝试在 this.jwtService.sign 函数中设置密钥时,例如
const accessToken = this.jwtService.sign(payload, 'secretkey' ,{ expiresIn: '60s'})
Run Code Online (Sandbox Code Playgroud)
我有错误。它告诉我该函数只能获取两个参数。那么如何创建两个密钥并互相使用以获得正确的令牌呢?
在我的学习服务器上。我有两个关于用户及其种族的集合。Races 具有userId属性,以便了解哪些用户发起了这场比赛。我需要整合所有用户和所有种族的对象。
我有用户集合:
[
{
"_id": "5d938ec8b17e522018e327db",
"name": "max",
"surname": "buinevich",
"username": "axe",
"__v": 0
}
]
Run Code Online (Sandbox Code Playgroud)
和比赛集合:
[
{
"_id": "5d93ac4c7076dc212ce187d6",
"userId": "5d938ec8b17e522018e327db",
"stageId": "5d939e16d4e51d2eac81827d",
"title": "test race",
"time": 33,
"description": "test desc",
"__v": 0
}
]
Run Code Online (Sandbox Code Playgroud)
所以我需要让所有用户参加适当的比赛才能得到如下结果:
[
{
"_id": "5d938ec8b17e522018e327db",
"name": "max",
"surname": "buinevich",
"username": "axe",
"races": [{
"_id": "5d93ac4c7076dc212ce187d6",
"userId": "5d938ec8b17e522018e327db",
"stageId": "5d939e16d4e51d2eac81827d",
"title": "test race",
"time": 33,
"description": "test desc",
"__v": 0
}]
"__v": 0
}
]
Run Code Online (Sandbox Code Playgroud)
我不想在集合模式中使用引用。也许是猫鼬聚合之类的东西。
我有这样的数组。可以无限数量的嵌套
const myArray = [
{
id: 1,
children: [
{
id: 3,
children: []
}
]
},
{
id: 2, children: []
}
]
Run Code Online (Sandbox Code Playgroud)
请帮助我通过 id 删除任何对象并返回没有它的新数组。
i have tree array of nested objects. Depending on the type of element I want to give it the necessary icon.
const treeData = [
{
id: 1,
type: "FOLDER",
children: [
{
id: 2,
type: "FILE"
},
{
id: 2,
type: "FOLDER",
children: []
},
]
}
]
Run Code Online (Sandbox Code Playgroud)
Unlimited number of nesting possible in folders. Output should be like that.
const treeData = [
{
id: 1,
type: "FOLDER",
icon: "folder-icon"
children: [
{
id: 2,
type: "FILE",
icon: …Run Code Online (Sandbox Code Playgroud)