Skip to content

Commit

Permalink
correcting the redirect of url
Browse files Browse the repository at this point in the history
  • Loading branch information
faisal-kn committed Dec 28, 2021
1 parent f158d91 commit 4aa2e61
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/direct.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React from "react";
import { useEffect, useContext } from "react";
import { Redirect, useParams } from "react-router-dom";
import axios from "axios";
import AuthContext from "./context/auth-context";

const Direct = () => {
const { shortenedURL } = useParams();
const ctx = useContext(AuthContext);

React.useEffect(() => {
useEffect(() => {
const getURL = async () => {
const options = {
url: `https://urlshortdev.herokuapp.com/api/v2/shorturl/${shortenedURL}`,
Expand All @@ -16,14 +18,14 @@ const Direct = () => {
console.log(res);
return res.data.data.url.fullUrl;
};
// getURL().then((res) => window.open(res, "_blank"));
getURL().then((res) => (window.location.href = res));
}, [shortenedURL]);
if (ctx.isLoggedIn) getURL().then((res) => window.open(res, "_blank"));
if (!ctx.isLoggedIn) getURL().then((res) => (window.location.href = res));
}, [ctx, shortenedURL]);

return (
<>
{/* <Redirect to="/home"></Redirect> */}
<div>we are redirecting</div>
{ctx.isLoggedIn && <Redirect to="/home"></Redirect>}
{!ctx.isLoggedIn && <div></div>}
</>
);
};
Expand Down

0 comments on commit 4aa2e61

Please sign in to comment.