使用NextAuth.js,如何在不注销并再次登录的情况下更新会话对象内的值?
例如,一旦用户登录,我就会使用会话中存储的 URL 来显示用户的头像。
我还提供用户更改他的头像,因此我希望session.user.image使用头像的新路径进行更新和持久化。我将所有数据存储在 MongoDB 中。我怎样才能做到这一点?现在唯一的解决方案是要求用户退出并重新登录,但这对我来说听起来不是一个可以接受的解决方案:)
我的第一个想法是在用户更新他的头像后更新这个会话对象,但我不知道如何做到这一点。
import React from 'react'
import { signIn, signOut, useSession } from 'next-auth/client'
export default function Page() {
const [ session, loading ] = useSession()
return <>
{session && <>
<img src={session.user.image} />
<button onClick={signOut}>Sign out</button>
</>}
</>
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试以 HTML 格式导出使用 Lexical 开发的 RTE 内容。为此,我有一个按钮,其handleClick功能应该是console.logHTML 中 RTE 的内容。
当我尝试将内容导出为字符串化 JSON 时,没有问题,我可以看到我的内容,例如:
{"root":{"children":[{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"test content","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1}],"direction":"ltr","format":"","indent":0,"type":"root","version":1}}
Run Code Online (Sandbox Code Playgroud)
然而,当我尝试将内容转换为 HTML 时,我仍然得到一个空字符串。
知道我在这里可能做错了什么吗?以下是将内容导出为 HTML 的函数:
import { $generateHtmlFromNodes } from '@lexical/html';
const handleClick = (editor: LexicalEditor) => {
editor.update(() => {
const editorState = editor.getEditorState();
const jsonString = JSON.stringify(editorState);
console.log('jsonString', jsonString);
const htmlString = $generateHtmlFromNodes(editor);
console.log('htmlString', htmlString);
});
};
Run Code Online (Sandbox Code Playgroud)
谢谢
我想将我从 Google firestore 获得的时间戳转换为我的 vueApp 中的天数和月数。
我得到一个这样的对象 Object { seconds: 1549843200, nanoseconds: 0 }
<template>
<div v-for="note in notes" :key="note.id" class="note">
<div class="note_dates">
<span class="day">{{note.day}}</span>
<span class="month">{{note.month}}</span>
.........
</template>
<script>
export default {
data() {
return {
notes: []
};
},
methods: {},
created() {
notesCollection.get().then(querySnapshot => {
querySnapshot.forEach(doc => {
const query = {
id: doc.id,
content: doc.data().content,
day: doc.data().created_on,
month: doc.data().created_on
};
this.notes.push(query);
});
});
}
Run Code Online (Sandbox Code Playgroud)
该值created_on是 firestore 集合中的时间戳
因此,在我的视图组件中,我只想回显时间戳中的日期和月份。
请帮我解决下图中显示的错误。
它说:
Error parsing XML, line 5, column 71: The reference to entity "display" must end with the ';' delimiter
Run Code Online (Sandbox Code Playgroud)
<strike>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet"/>
</strike>
Run Code Online (Sandbox Code Playgroud)

收到此错误...
编辑route.js以反映更改
./app/config/routes.js中的错误找不到模块:错误:无法在/ Users / sam / Desktop / battle / app / config @ ./app/config/routes.js中解析模块'react-rounter'2: 19-43
我已经将webpack和react-react-dom-react-router-babel等安装到了我的npm软件包中。当我运行npm start时,出现上述错误。这是我的package.json / webpack config / router.js文件
package.json
{
"name": "battle",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"production": "webpack -p",
"start": "webpack-dev-server"
},
"author": "Sam Schaefer <smmschaefer@gmail.com>",
"license": "ISC",
"dependencies": {
"react": "^15.4.0",
"react-dom": "^15.4.0",
"react-router": "^3.0.0"
},
"devDependencies": {
"babel-core": "^6.18.2",
"babel-loader": "^6.2.8",
"babel-preset-react": "^6.16.0",
"html-webpack-plugin": "^2.24.1",
"webpack": "^1.13.3",
"webpack-dev-server": "^1.16.2"
}
}
Run Code Online (Sandbox Code Playgroud)
webpack.config
var HtmlWebpackPlugin = require('html-webpack-plugin')
var HTMLWebpackPluginConfig …Run Code Online (Sandbox Code Playgroud)