首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >redux-下一个包装器,带有supabase v2 ssr

redux-下一个包装器,带有supabase v2 ssr
EN

Stack Overflow用户
提问于 2022-10-21 16:02:04
回答 1查看 40关注 0票数 1

supabase V2之前,我获得了我的数据,并使用这样的redux存储在其中:

不幸的是,supabase V2破坏了redux-next-wrapper的一些功能

代码语言:javascript
复制
export const getServerSideProps = wrapper.getServerSideProps(
  (store) => async ({ req }) => {
    const { user } = await supabase.auth.api.getUserByCookie(req);
    if (user === null) {
      return {
        redirect: {
          permanent: false,
          destination: "/auth",
        },
        props: {},
      };
    }
    if (user) {
      async function getData() {
        let { data, error, status } = await supabase
          .from("table")
          .select(`id`)
          .eq("id", user.id);
        store.dispatch(writeUserData(data));
        return data;
      }

      return {
        props: {
          data: await getData(),
        },
      };
    }
  }
);

有什么想法吗?如何用withPageAuth()实现相同的功能?

代码语言:javascript
复制
export const getServerSideProps = withPageAuth({
  redirectTo: '/foo',
  async getServerSideProps (ctx, supabase) {
    // Access the user object
    const {
      data: { user }
    } = await supabase.auth.getUser()

    return { props: { id: user?.id } }
  }
})
EN

回答 1

Stack Overflow用户

发布于 2022-10-23 22:25:46

这与您已经拥有的类似,只是重定向已经由withPageAuth处理了。

代码语言:javascript
复制
export const getServerSideProps = withPageAuth({
  redirectTo: '/auth',
  async getServerSideProps (ctx, supabase) {
    // Access the user object
    const {
      data: { user }
    } = await supabase.auth.getUser()

    let { data, error, status } = await supabase
      .from("table")
      .select(`id`)
      .eq("id", user.id);
    store.dispatch(writeUserData(data));

    return { props: { data } }
  }
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74156313

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档