plane/lib/hoc/withAuthWrapper.tsx
2022-11-19 19:51:26 +05:30

31 lines
820 B
TypeScript

import React, { useEffect } from "react";
// next
import type { NextPage } from "next";
// axios configurations
import { setAxiosHeader } from "configuration/axios-configuration";
// redirect
import redirect from "lib/redirect";
const withAuthWrapper = (WrappedComponent: NextPage) => {
const Wrapper: NextPage<any> = (props) => {
useEffect(() => {
if (props?.tokenDetails && props?.tokenDetails?.access_token) {
setAxiosHeader(props.tokenDetails.access_token);
}
}, [props]);
return <WrappedComponent {...props} />;
};
Wrapper.getInitialProps = async (ctx) => {
const componentProps =
WrappedComponent.getInitialProps &&
(await WrappedComponent.getInitialProps(ctx));
return { ...componentProps };
};
return Wrapper;
};
export default withAuthWrapper;