-
Notifications
You must be signed in to change notification settings - Fork 0
/
HiddenContent.tsx
41 lines (36 loc) · 1.14 KB
/
HiddenContent.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import React, { useState, useEffect } from "react";
import AuthForm from "../AuthForm/AuthForm";
import axios from "axios";
function HiddenContent(props: any) {
const { tokens } = props;
const refreshToken = tokens.newRefreshTkn;
// console.log(refreshToken);
// const MINUTE_MS = 300000;
// const test = 3000;
useEffect(() => {
const interval = setInterval(() => {
if (Object.keys(tokens).length === 0) {
axios
.post("http:https://localhost:5001/user/get-refresh-token", refreshToken)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
}, test);
return () => clearInterval(interval); // This represents the unmount function, in which you need to clear your interval to prevent memory leaks.
}, []);
return (
<>
<h1>HiddenContent</h1>
<p>
This is a page that can only be accessed via auth. It has refresh token
wrapped around this so that it will consistently check if the token is
expired.
</p>
</>
);
}
export default HiddenContent;