目前我正在尝试收集有关如何实现身份验证系统(登录)的知识。在我的研究期间,我尝试在我的后端实施基于 JWT 的解决方案。
我有一个快速服务器,它允许我注册一个用户,存储它的密码(加密)和它的电子邮件。
在登录之后,它会生成一个访问令牌(短期,5 分钟),以访问受保护的路由,以及一个刷新令牌(长期,7 天),以便在前一个过期后生成新的访问令牌。
在我当前的实现中,我将刷新令牌存储在我的数据库中,因此每次我想生成新的访问令牌时都可以使用它。
但这安全吗?据我了解,在我的数据库中存储访问令牌是危险的,因此最好创建一个短期存在的 cookie 存储。但是……刷新令牌?据我所知,这会很危险,因为它基本上允许生成新的访问令牌,所以我不明白为什么不简单地在我的数据库中存储一个长期存在的访问令牌,在每次登录时生成一个新的。
什么是刷新令牌呢?
由于我遵循了一些教程来实现这一点,这就是我的 refresh_token 路由的外观
//get a new access token with a refresh token
app.post('/refresh_token', (req, res) => {
const token = req.cookies.refreshtoken
//if no token in request
if(!token) return res.send({accesstoken : ''});
//if we have a token we verify it
let payload = null;
try{
payload = verify(token, process.env.REFRESH_TOKEN_SECRET);
}catch(err){
return res.send({accesstoken: ''});
}
//if token is valid check if user exist
const user = fakeDB.find(user => user.id === …Run Code Online (Sandbox Code Playgroud) 据我所知,React props 会保存您每次更新页面或导航到新页面时访问过的所有链接的历史记录。可以使用以下方式浏览此历史记录props.history.go(-number)
例如,如果我导航到
/home --> /home/startup --> /error
Run Code Online (Sandbox Code Playgroud)
我的历史记录将保存在某个地方["/home", "/home/startup", "/error"]
我触发
history.go(-2),我将被推送到 /home,并且历史堆栈将被重置到该点。
我问这个问题是因为我被迫保留一个自定义对象来跟踪所有用户导航,以便能够使用网站中的后退按钮将用户重定向到特定检查点。
例如:
const pushBack = () => {
let historyArr: Array<string> = getNavigationHistoryArr();
historyArr.reverse();
//check the amount of spots between our tracked history last element and the checkpoints
let spotsToRedirect: number = 0;
for (let i in historyArr) {
if (redirectCheckpoints.includes(historyArr[i])) {
break;
}
spotsToRedirect--;
}
console.log("sportsToRedirect: "+spotsToRedirect)
//whenever you have a long navigation stack
if (spotsToRedirect < 0 && spotsToRedirect * …Run Code Online (Sandbox Code Playgroud) 我在 fetch 函数的“fetchUrl”参数中收到以下错误
'string | 类型的参数 undefined' 不可分配给'RequestInfo' 类型的参数。
在这个函数中
let fetchUrl = getBaseUrlNative( process.env.APP_DATA, `/v2/marketing/app/file/${file}?cookies=${cookieSess}&expires=${Date.now()}`)
await fetch(fetchUrl, { method: 'get' , cache:"no-store" , headers: {
'Cache-Control': 'no-cache'
}})
.then(res => res.blob())
.then(res => { .......
Run Code Online (Sandbox Code Playgroud)
getBaseUrlNative 是
export const getBaseUrlNative = (eUrl : string | undefined, ext : string | undefined) => {
try {
if (!eUrl) throw new Error("Error .")
return ext ? eUrl+ext : eUrl;
} catch (err) {
console.log(err)
}
}
Run Code Online (Sandbox Code Playgroud) 我现在有这个
const canvas: any = canvasRef.current;
const context : any = canvas.getContext("2d");
Run Code Online (Sandbox Code Playgroud)
我已经给了他们任何价值观。
显然有一个上下文类型。
https://microsoft.github.io/PowerBI-JavaScript/modules/_node_modules__types_node_vm_d_._vm_.html
Run Code Online (Sandbox Code Playgroud)
但这是我需要的吗?
尽管如此,我不知道如何在画布上打字。
我有以下 hapi.js 服务器
const Hapi = require('hapi')
const Mongoose = require('mongoose')
const Wreck = require('wreck');
const server = new Hapi.Server({
"host": "localhost",
"port": 3000
})
Mongoose.connect('mongodb://localhost/myDB', { useNewUrlParser: true })
const BlockModel = Mongoose.model('block', {
height: Number,
size: Number,
time: Number
})
server.route({
method: "GET",
path: "/",
handler: async (request, h) => {
Mongoose.model.blocks.remove({}); //<------This is the part of the code I intend to use to delete the collection
const { res, payload } = await Wreck.get('https://api.url');
let myJson = …Run Code Online (Sandbox Code Playgroud) 为什么我不能转换这个 arr
let stringarr = "[2022/07/12, 2022/08/09]"
Run Code Online (Sandbox Code Playgroud)
到此arr
let arr = JSON.parse(stringarr) ---> error
Run Code Online (Sandbox Code Playgroud)
JSON 中位置 5 处出现意外标记 /
我有一个使用 classBased react 的组件,它运行良好,我决定切换到 usestate 并且它停止工作。现在handlechange以随机方式记录状态,但是不能正常工作
我的 handlechange 和 useState
const [state, setState] = useState({
email: "",
password: "",
wrongCombo: false,
serverError: false
})
const handleChange = (evt) => {
const target = evt.target;
const value = target.value;
const name = target.name;
console.log(name)
console.log(value)
setState({
[name]: value
});
}
Run Code Online (Sandbox Code Playgroud)
我的handlesubmit(它在console.log中检测随机值,找不到逻辑,但日志不会按照handlechange中输入的那样获得两个值)
const handleSubmit = (event) => {
event.preventDefault();
const { email, password } = state;
console.log(state)
props.login(email, password, "login").
then(data => {
}).catch((err) => {
if (err == "Error: Request failed …Run Code Online (Sandbox Code Playgroud) 有一些方法可以使用 unicode 在 javascript 中打印字母,例如
console.log(\u0062)产生 ab ,所以它与 put 相同console.log(b)
但现在,我确实知道有一些方法可以 console.log 粗体字母,例如
console.log('')
Run Code Online (Sandbox Code Playgroud)
在控制台中打印粗体字。
但是,例如以粗体打印的函数是什么?
这是我的想法
const printBold = (word: string) => {
//splits the string, gets every letter, and replaces with the bold unicode equivalent
}
Run Code Online (Sandbox Code Playgroud)
但是...我无法找到粗体字母的等效 unicode,或者创建以粗体登录的函数的方法。
也许我可以做类似的事情
const map = {
"a": "bold_a",
"b": ''
}
Run Code Online (Sandbox Code Playgroud)
并向转换器提供该数据,但是...我从哪里获得粗体 unicode 或字符?我唯一能找到的,我从这个答案复制了它们 /sf/answers/4939874481/
javascript ×4
reactjs ×2
typescript ×2
express-jwt ×1
fetch-api ×1
fonts ×1
jwt ×1
jwt-auth ×1
mongodb ×1
mongoose ×1
node.js ×1
unicode ×1