身份验证不适用于Supplier和Node.js

jhkqcmku  于 11个月前  发布在  Node.js
关注(0)|答案(2)|浏览(123)

我不确定这是否可能,但我正在尝试使用Node.js的Supplement。我从React前端获取代码,这个link,它工作正常。
下面是我的代码

client.js

const { createClient } = require('@supabase/supabase-js')

const supabaseUrl = "MY_URL"
const public_anon_key = "MY_ANON_KEY"
const supabase = createClient(supabaseUrl,public_anon_key)

exports.supabase = supabase

字符串

app.js

const { supabase }  = require('./client')

async function signOut() {
        /* sign the user out */
        await supabase.auth.signOut();
}

async function signInWithGithub() {
        /* authenticate with GitHub */
        await supabase.auth.signIn({
                provider: 'github'
        });
}

async function printUser() {
        const user = supabase.auth.user()
        console.log(user.email)
}

signInWithGithub()
printUser()
signOut()


我是Node.js的新手,我怀疑Promises缺少了一些错误。是否可以从Supplies中检索user数据,如果可以,我的代码缺少了什么?
谢谢
编辑:标题

dluptydi

dluptydi1#

我不知道Supplies是做什么的,但这个问题似乎与Promise有关
尝试按以下方式更改您的app.js

const { supabase }  = require('./client')

function signOut() {
        /* sign the user out */
        supabase.auth.signOut();
}

function signInWithGithub() {
        /* authenticate with GitHub */
        return  supabase.auth.signIn({
                provider: 'github'
        });
}
function printUser() {
        const user = supabase.auth.user()
        console.log(user.email)
}

signInWithGithub().then(() => {
   printUser()
   return signOut()

})

字符串

wswtfjt7

wswtfjt72#

由于@supabase/supabase-js到v2(在编写时)是为JAMstack开发人员准备的,因此需要一些额外的配置才能将其用于Node.js环境。
您将需要一些额外的配置:

// ANON_KEY and ANON_URL are string constants from your project
createClient(ANON_URL, ANON_KEY, {
    auth: { persistSession: false, autoRefreshToken: false },
})

字符串
这将禁止客户端尝试存储和刷新会话,因为服务器/脚本环境中没有localStorage。

相关问题