sending the auth from libracart to the add endpoints
This commit is contained in:
parent
767ca5ef97
commit
093ad7b2ad
3 changed files with 21 additions and 12 deletions
|
|
@ -25,27 +25,22 @@ export default function LibraCartAccess() {
|
|||
const [primaryUser, setPrimaryUser] = useState("");
|
||||
const [libracartUsername, setLibraCartUserName] = useState("");
|
||||
const [libracartCode, setLibraCartCode] = useState<string | null>("");
|
||||
const [libracartAuth, setLibraCartAuth] = useState<string | null>("");
|
||||
//const [activeStep, setActiveStep] = useState<number>(0);
|
||||
const userAPI = useUserAPI();
|
||||
const libracartAPI = useLibraCartProxyAPI();
|
||||
//const [dataOps, setDataOps] = useState<pond.DataOption[]>([]);
|
||||
const { openSnack } = useSnackbar();
|
||||
const search = useLocation().search;
|
||||
const searchParams = new URLSearchParams(search);
|
||||
//const [{ as }] = useGlobalState();
|
||||
// const integration_url = process.env.REACT_APP_LIBRACART_INTEGRATION_URL;
|
||||
const integration_url = import.meta.env.VITE_LIBRACART_INTEGRATION_URL;
|
||||
|
||||
|
||||
const submitNewOrganization = () => {
|
||||
if (libracartCode) {
|
||||
if (libracartCode && libracartAuth) {
|
||||
libracartAPI
|
||||
.addAccount(teamKey, primaryUser, libracartCode, libracartUsername)
|
||||
.addAccount(teamKey, primaryUser, libracartCode, libracartAuth, libracartUsername)
|
||||
.then(resp => {
|
||||
//the code was used so remove it from local storage
|
||||
if (localStorage.getItem("code")) {
|
||||
localStorage.removeItem("code");
|
||||
}
|
||||
openSnack("Added New Libra Cart Account Link");
|
||||
})
|
||||
.catch(err => {
|
||||
|
|
@ -72,9 +67,12 @@ export default function LibraCartAccess() {
|
|||
// }, [searchParams, libracartCode]);
|
||||
|
||||
useEffect(() => {
|
||||
let code = new URLSearchParams(window.location.search).get("state"); // not sure if the state is correct here i thought it should be the access_token
|
||||
if (code) {
|
||||
let code = new URLSearchParams(window.location.search).get("state"); // this is the account_code
|
||||
let auth = new URLSearchParams(window.location.search).get("authorization_token"); // this is the authorization used to verify where it came from
|
||||
|
||||
if (code && auth) {
|
||||
setLibraCartCode(code);
|
||||
setLibraCartAuth(auth);
|
||||
setOpenDialog(true);
|
||||
}
|
||||
}, [window.location]);
|
||||
|
|
@ -133,7 +131,14 @@ export default function LibraCartAccess() {
|
|||
fullWidth
|
||||
variant="outlined"
|
||||
value={libracartCode}
|
||||
onChange={e => setLibraCartCode(e.target.value)}
|
||||
/>
|
||||
<TextField
|
||||
margin="dense"
|
||||
label="authorization token"
|
||||
disabled
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
value={libracartAuth}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ export interface ILibraCartProxyAPIContext {
|
|||
teamKey: string,
|
||||
userID: string,
|
||||
libracartCode: string,
|
||||
libracartAuth: string,
|
||||
libracartUsername: string
|
||||
) => Promise<AxiosResponse<pond.AddLibraCartAccountResponse>>;
|
||||
//list organizations
|
||||
|
|
@ -51,6 +52,7 @@ export default function LibraCartProvider(props: PropsWithChildren<Props>) {
|
|||
teamKey: string,
|
||||
userID: string,
|
||||
libracartCode: string,
|
||||
libracartAuth: string,
|
||||
libracartUsername: string
|
||||
) => {
|
||||
return post<pond.AddLibraCartAccountResponse>(
|
||||
|
|
@ -61,6 +63,8 @@ export default function LibraCartProvider(props: PropsWithChildren<Props>) {
|
|||
userID +
|
||||
"&code=" +
|
||||
libracartCode +
|
||||
"&auth=" +
|
||||
libracartAuth +
|
||||
"&libracartUsername=" +
|
||||
libracartUsername
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue