Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【又来请教啦大佬 登录 - cookie 缓存】 #27

Closed
pengxinseo opened this issue Apr 28, 2024 · 7 comments
Closed

【又来请教啦大佬 登录 - cookie 缓存】 #27

pengxinseo opened this issue Apr 28, 2024 · 7 comments

Comments

@pengxinseo
Copy link

async function init() { const user_id = sessionStorage.getItem("user_id"); if (user_id) { await getUserById(user_id); } else { if (status == 'authenticated') { await getUserByEmail(session.user.email); } else if (status == 'unauthenticated') { console.log('未验证'); setIntervalUserData(undefined); // https://www.npmjs.com/package/google-one-tap const options = { client_id: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID, // required auto_select: false, // optional cancel_on_tap_outside: false, // optional context: 'signin', // optional }; googleOneTap(options, (response) => { const token = response.credential; getUserOneTap(token); }); } } }

这个地方的 这段代码 我感觉 就没执行呀

googleOneTap(options, (response) => { const token = response.credential; Cookies.set("iuu_userInfo", 1111, { expires: 7 }); getUserOneTap(token); });

    然后我 添加了   没结果 ,sessionStorage,也是没结果  ,然后 第一次授权成功后的 函数是哪一个呀  ,我想 set一个cookie键值对 ,这样不用每个  页面 都去数据库请求用户的信息了 ,
@littletry
Copy link
Collaborator

照你自己想法调吧,oneTap 你不想要就去掉,用户没登录时才会调用oneTap触发右上角弹出谷歌登录的一键登录

@pengxinseo
Copy link
Author

pengxinseo commented Apr 28, 2024 via email

@littletry
Copy link
Collaborator

littletry commented Apr 28, 2024

除了 oneTap,上边的逻辑是点登录按钮触发,next-auth

@pengxinseo
Copy link
Author

获取数据库的数据 Sources 里面 html 没有数据问题

1111

为了接解决问题开始查阅了资料 然后发现 使用 【getServerSideProps
可以服务端获取数据渲染 ,

然后尝试了 几次 这个 getServerSideProps 好像没执行 有点摸不住头脑啦 ,

后来我又看了你的 LoadingModel 是不是 就是代替 获取数据库 等待 成功后才开始 渲染 html 元素的 ?

还望大佬指点指点一二

大佬 五一假期快乐哈 可以你等你假期过完回复也行哈 。十分感谢

@pengxinseo
Copy link
Author

大佬 不忙了,帮忙看下呗

@littletry
Copy link
Collaborator

这是 APP router 不是 Pages router,自己去看 next 官网怎么获取数据的
在 page.tsx 里面有 await 那样获取数据就是后端渲染了

@littletry
Copy link
Collaborator

大佬 不忙了,帮忙看下呗

加个微信?不怎么看 github 消息。这是我的微信号: DevShot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants