我正在尝试使用 Nextjs 13 与 Next-auth 和 Apollo 客户端。为此,我们用提供者包装根布局,但我们也需要'use client'指定。我对图书馆没有任何问题。
但令我困惑的是,nextjs 13 app dir 默认使用服务器优先的方法,如果我将根布局视为客户端,它是否会使所有页面成为客户端?因为,据我所知,根布局是整个路线的父级
我想要transition-transform和transition-shadow,而不是两者都不是transition-all,也不是只有一个。让这两个不起作用,我找不到它的文档,我尝试像这样玩:transition-[transform, shadow]显然没有用。
基本上,我有卡片,你将鼠标悬停在上面,它会放大一点并留下阴影。
className='hover:scale-105 hover:shadow-2xl transition-transform transition-shadow'
如何将过渡性质transform和放在shadow一起?
我的应用程序有白色和黑色主题,这就是我不想只是放置的方式,transition-all因为它在切换主题时会闪烁。
我们正在我们的网站上进行 OTP 身份验证。因此,为了获得授权,访问者在输入中输入他的电话号码,我们向他发送一个 OPT 号码,他再次输入发送的选项,然后如果匹配,我们向他发送他的帐户凭据(令牌、用户 ID)(如果存在),或者我们创建新的,我们希望使用 next-auth 在会话中保存该凭证。
这是我到目前为止所得到的:
export default NextAuth({
providers: [
CredentialsProvider({
credentials: {
phoneNumber: { label: 'PhoneNumber', type: 'text' },
code: { label: 'Code', type: 'text' },
type: { label: 'Type', type: 'text' },
},
async authorize(credentials, req) {
const user_needs = await requests.auth.signInEnterOtp(
credentials.phoneNumber,
credentials.code,
credentials.type
)
return user_needs.ok ? true : null
},
}),
],
callbacks: {
async session({ session, user, token }) {
return session
},
},
secret: process.env.JWT_SECRET,
})
Run Code Online (Sandbox Code Playgroud)
我需要保存user_needs会话中的内容,但如何将其传递 …
我使用 mongodb 模板安装了 next.js 应用程序:
npx create-next-app --e with-mongodb my-app
Run Code Online (Sandbox Code Playgroud)
并安装了 TypeScript。我需要转换/lib/mongodb.js为 TypeScript
目前看起来像这样,几乎没有类型变化
// lib/mongodb.ts
import { MongoClient } from 'mongodb'
const uri = process.env.MONGODB_URI
const options = {}
let client
let clientPromise: MongoClient
if (!process.env.MONGODB_URI) {
throw new Error('Please add your Mongo URI to .env.local')
}
if (process.env.NODE_ENV === 'development') {
if (!global._mongoClientPromise) {
client = new MongoClient(uri, options)
global._mongoClientPromise = client.connect()
}
clientPromise = global._mongoClientPromise
} else {
client = new MongoClient(uri, options)
clientPromise = …Run Code Online (Sandbox Code Playgroud) 这就是我们在网站上授权用户的方式
signIn('credentials', {
phoneNumber: verifiedPhone,
code: otp.data,
type: 'phone',
redirect: false,
}).then((res) => {
console.log(res) // default response {error,status,ok,url}
// How can i add additional data to this response, in my case user session
// if (!res.user.name) openModal('add_name')
// else toast.success('You are all set!')
});
Run Code Online (Sandbox Code Playgroud)
默认情况下,signIn 将返回一个 Promise,解析为:
{
error: string | undefined
status: number
ok: boolean
url: string | null
}
Run Code Online (Sandbox Code Playgroud)
我们想将自定义数据添加到此承诺回报中。
实际上我们想要做的是让用户登录,如果用户是新用户,他/她应该没有用户名,因此会打开一个模式,输入他/她的用户名,然后我们更新下一个身份验证会话。
[...nextauth].js:
...
async authorize(credentials, req) {
// check the code here
const res = await …Run Code Online (Sandbox Code Playgroud) next.js ×4
next-auth ×2
javascript ×1
mongodb ×1
next.js13 ×1
reactjs ×1
tailwind-css ×1
typescript ×1