【发布时间】:2022-10-24 06:25:46
【问题描述】:
在supabase V2 之前,我得到了我的数据并使用 redux 存储,如下所示:
supabase 不幸的是,V2 破坏了 redux-next-wrapper 的一些功能
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() 实现相同的功能?
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 } }
}
})
【问题讨论】:
标签: reactjs redux next.js supabase