我正在使用 Next-Auth v4.22.1 和 NextJS 13。
我正在尝试在 [...nextauth].js jwt 回调中注销用户。
我知道signOut()仅在客户端可用。如果在服务器端使用它,我们将收到“ReferenceError:窗口未定义”错误。
我对 /api/auth/signout 的 POST 请求不起作用。
我收到错误
nextauth-signout-requests.js - Fetch Error SyntaxError: Unexpected token E in JSON at position 0
API handler should not return a value, received object.
API resolved without sending a response for /api/nextauth-signout-requests, this may result in stalled requests.
Run Code Online (Sandbox Code Playgroud)
我来自 nextauth-signout-requests.js 的 POST 代码:
const NextAuthSignOutReq = async (req, res) => {
if (req.method === 'POST') {
try {
// Sign out the user
const signOut …Run Code Online (Sandbox Code Playgroud) 我如何以编程方式在服务器端的 Next-Auth 中注销用户?
/api/auth/[...nextauth].js 里面有一个 jwt 函数:
const callbacks = {
async jwt ({ token, user }) {
// How to sign out a user?
signOut(); <--- can't use this on the server side
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,signOut() 函数仅适用于客户端。如果在这里使用它会产生错误。
我已经阅读了非常简单的 Next Auth REST API 页面,但无法对“/api/auth/signout”进行 POST 调用。如果这是正确的方法,有人可以向我展示一些工作代码吗?它需要任何类型的授权令牌吗?
https://next-auth.js.org/getting-started/rest-api
谢谢!
我正在运行 Ubuntu 22.04 并尝试安装 .NET 7.0.5
我尝试了多种不同的安装 .NET 7 的方法,但它们似乎都不允许我使用 dotnet build 或 dotnetpublish 命令。
Ubuntu 似乎无法识别我的 SDK 已安装,这似乎是某种问题。
dotnet publish -c Release -r linux-x64 --self-contained false
You must install or update .NET to run this application.
App: /usr/share/dotnet/sdk/7.0.302/dotnet.dll
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '7.0.5' (x64)
.NET location: /usr/share/dotnet/
No frameworks were found.
Run Code Online (Sandbox Code Playgroud)
我尝试显示 dotnet 版本:
root@localhost:~# dotnet --version
The command could not be loaded, possibly because:
* You intended to execute a .NET application:
The application '--version' does not …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写 cypress 测试来检查数据是否从 API 接收到我的数据表中。
一项测试检查数据,另一项测试检查 API 中没有数据时是否有错误消息。
为了模拟 API 的响应(一种有数据,一种没有),我使用 cy.intercept()。
我似乎无法在我的单个测试文件中获得两个单独的拦截。
在同一个 cypress 测试文件中测试多个不同拦截的推荐程序是什么,或者它们应该在单独的文件中?
任何帮助表示赞赏!
describe('Display Data Page', () => {
beforeEach(() => {
// Fake the backend Http response using the json file in our cypress fixtures folder.
cy.intercept('GET', 'https://localhost:3000/GetData', {fixture:'my_data.json'}).as('my_data');
cy.visit('/display-data');
});
it('Should display a list of my data', () => {
cy.wait('@my_data');
cy.get('.dataGrid').should('not.be.empty');
cy.get('.dataGrid').should("contain", "Blah");
});
it('Should display a error message when api is offline', () => {
// Reply with a HTTP 400 bad …Run Code Online (Sandbox Code Playgroud) 我在我的 React 应用程序中使用动态类名称,它们是由 CSS 模块生成的。
编译className={styles.myclass}成class="Myclass__1234"这样,cypresscy.get(.'myclass')将无法工作。
举个例子:
import styles from 'styles/About.module.css';
const About = () => {
return (
<div className={styles.about}>
<h1 className={styles.title}>About Me Page</h1>
</div>
);
};
export default About;
Run Code Online (Sandbox Code Playgroud)
要检查标题文本,您需要执行以下操作:
cy.get('About_title__1234').should('not.be.empty');
Run Code Online (Sandbox Code Playgroud)
这意味着我每次都必须深入开发工具才能找到真正的类名。
我还可以使用其他方法吗?
我想cy.get('h1')可以,但稍后我可能需要在页面上使用多个 h1 标签。