gpt4 book ai didi

authentication - JWT token 未保存在数据库中

转载 作者:行者123 更新时间:2023-12-04 15:03:39 31 4
gpt4 key购买 nike

用户认证返回token,但没有保存在数据库中
AuthController:

'use strict'

const User = use("App/Models/User");

class AuthController {
async registrar({ request }) {
const data = request.only(["username", "email", "password"]);

const user = await User.create(data);

return user;
}

async autenticar({ request, auth }) {
const { email, password } = request.all();
const retorno = {};
let token;
if (token = await auth.attempt(email, password)) {
const user = await User.findBy('email', email)
retorno.token = token.token;
retorno.user = user.username;
retorno.id = user.id;
} else {
retorno.data = "E-mail ou senha Incorretos";
}
return retorno;
}

}

module.exports = AuthController
我的请求
POST http://localhost:3333/autenticar
{
"email":"c@gmail.com",
"password": "123456"
}
我的回复
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjEsImlhdCI6MTYxNTI5Njk4MH0.O0X4gGIEtMiZfEH3VxWbffsCZQDUhgEv0CymA0dB6z8",
"user": "gui",
"id": 1
}
request and response auth
请求后我的 token 表
0 tokens
我在另一个网站上发现了同样的问题,但我没有可以提供帮助的答案。

最佳答案

AdonisJS 不存储 JWT数据库中的 token 。只有 refresh token被存储。

Why JWT token are not stored?


^ JWT 没有保存在数据库中,因为它没有用。所有 JWT token 都经过签名,因此服务器可以轻松检查 token 是否有效。有用的答案 Where should I store jwt token for authentication on server side
JWT token 不像不透明 token 那样工作。不透明的 token 保存在数据库中,后端检查 token 是否存在,然后授予访问权限。
有用的链接: https://medium.com/@piyumimdasanayaka/json-web-token-jwt-vs-opaque-token-984791a3e715

了解 JSON 网络 token :
  • https://www.javainuse.com/spring/jwt
  • https://auth0.com/learn/token-based-authentication-made-easy/
  • 关于authentication - JWT token 未保存在数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66548358/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com