You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将React登录用户关联到Passport.js EveOnline数据库?

问题描述

技术栈为React前端、Node.js+Express后端,使用passport-local和passport-eveonline。已实现Passport.js基础功能,能将Eve角色数据存入数据库,但无法获取React端当前登录用户的会话信息(如用户名或ID),没法把该用户关联到Eve角色的数据库记录里。

补充细节

网站账号创建功能正常,passport-eveonline可正常工作,但缺少React端当前登录用户的账号信息。需求是将React端当前登录用户关联到存储Eve角色的数据库中,寻求指导或协助。

相关代码

获取passport-eveonline数据的代码

passport.use(new EveOAuth2Strategy({
    clientID: eve_client,
    secretKey: eve_secret,
    callbackURL: "http://localhost:3001/auth/eveonline/callback",
    state: process.env.EVE_STATE,
    passReqToCallback: true
},
    async function (req, accessToken, refreshToken, profile, cb) {

        const character = await Accounts.findOrCreate({ where: { characterID: profile.CharacterID }, defaults: { userID: req.body.id, characterID: profile.CharacterID, characterName: profile.CharacterName, accessToken: accessToken, refreshToken: refreshToken } })
        if (character) {
            await Accounts.update({ characterID: profile.CharacterID }, { where: { characterID: profile.CharacterID, characterName: profile.CharacterName, accessToken: accessToken, refreshToken: refreshToken } });
            return cb(`${profile.CharacterName} has been added/updated. You can close this now \\o/`, null);
        }
    }
));

跳转至角色选择页面的路由

app.get('/auth/eveonline',
    passport.authenticate('eveOnline', { scope }));

角色选择后的回调路由

app.get('/auth/eveonline/callback',
    passport.authenticate('eveOnline', {
        successRedirect: '/dashboard',
        failureRedirect: '/failed',
        failWithError: true,
    })
);

内容的提问来源于stack exchange,提问作者Skippy The Canadian Kangaroo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 03:22:29