跳到主要内容
ArcBlock Community

Control logging button from pages kit

Twelve
支持
pages-kitresolved

Hey team — right now in our app we’ve got a custom Cart that requires login before checkout. We can detect login state using fetch, but it’s a little fidgety since we’re basically listening for the signal rather than triggering it.

Is there any way for us to manually trigger the Passport login flow from a custom button inside our component (instead of relying on the person icon in the corner)?

Like an “onClick={() => passport.login()}”

or a hook from usePassport() would be ideal.

We just want a cleaner way to handle login so the Cart can control the flow directly.

Thanks 🙏

— 12inchapps

2 条回复

xiaoliang10个月前

我们提供了 useSessionContext 来获取用户信息,检查登录状态,调起登录功能。

下面这个段伪代码可以参考:

javascriptCopy
import { useSessionContext } from '@blocklet/pages-kit/builtin/session';

export default (props) => {

const { session } = useSessionContext();

const handleClickPrimary = () => {

// Check if session.user has a value; if it does, it means logged in.
    if (session.user) {
      window.location.href = linkPrimary;
    } else {
    
// Trigger login
      session.login(() => {
        window.location.href = linkPrimary;
      });
    }
  }
}
Twelve10个月前

Thank you this is perfect!

回复