esd*_*esd 5 next.js supabase-js
我正在使用 Supabase 和 Next.js 12.3.4 开发一个项目,并且我已经使用本教程设置了 Google 登录:Supabase Login with Google。当我运行项目时,终端反复警告
No storage option exists to persist the session, which may result in unexpected behavior when using auth.
If you want to set persistSession to true, please provide a storage option or you may set persistSession to false to disable this warning.
Run Code Online (Sandbox Code Playgroud)
这是登录代码:
import supabaseClient from "./supabaseClient";
export default async function signInWithGoogle() {
const { data, error } = await supabaseClient.auth.signInWithOAuth({
provider: 'google',
options: {
redirectTo: 'http://localhost:3000/account'
}
})
}
Run Code Online (Sandbox Code Playgroud)
对其他人关于此问题的帖子的回应建议遵循本教程,我尝试了这一点,因为我的项目也有一个页面目录。但是,本教程引用了带有 App 函数的 src/App.jsx 文件,而我有一个带有“export default class MyApp extends App”的pages/_app.js 文件,本教程对此不起作用 - 尝试使用 _app.js 中推荐的代码导致Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
这是我的_app.js文件:
import App from 'next/app'
import Head from 'next/head'
import React from 'react'
import { Analytics } from '@vercel/analytics/react';
import font from "/components/styles.css";
export default class MyApp extends App {
static async getInitialProps({ Component, ctx }) {
let pageProps = {}
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx)
}
return { pageProps }
}
render() {
const { Component, pageProps } = this.props
return (
<>
<Head>
<title>words</title>
</Head>
<Component {...pageProps} />
<Analytics />
</>
)
}
}
Run Code Online (Sandbox Code Playgroud)
如何解决存储错误?(我对所有这些技术都很陌生,所以这可能有一个明显的解决方案。)谢谢!
小智 6
当我在节点中使用supabase时我也遇到了这个问题,希望它可以解决你的问题
const supabase = createClient(supabaseUrl, supabaseKey, {
auth: { persistSession: false },
});
Run Code Online (Sandbox Code Playgroud)
谢谢你们的回复。我最终所做的(不幸的是,它没有用我最初所说的参数回答这个问题)是将项目升级到 Nextjs 13(因为这使得项目的另一个方面更容易执行)。升级后,我根据本教程设置了Supabase:https://supabase.com/docs/guides/getting-started/tutorials/with-nextjs并更改了signInWithGoogle 函数:
import { createClientComponentClient } from "@supabase/auth-helpers-nextjs"
export default async function signInWithGoogle() {
const supabase = createClientComponentClient()
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'google',
options: {
redirectTo: 'http://localhost:3000/auth/callback'
}
})
}
Run Code Online (Sandbox Code Playgroud)
项目升级后错误停止。
| 归档时间: |
|
| 查看次数: |
5700 次 |
| 最近记录: |