You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What we did is write a component called ProtectedRoute that either returned a Route or a Redirect depending on whether the user was logged in. If they were logged in it returned the route, otherwise a redirect to the login page. We then put it in our router switch statement whenever we wanted a protected route. The component ended up looking like this:
validateExp is another one we wrote ourselves. It compares the time in the JWT against the present.
This method doesn't stop a hacker getting to the route. That would require a server request. It just stops a normal user who isnt logged in getting to a route, so it makes routes semi-protected. For us, the specifics, like the cards on the page, required a server request, and there we checked that the JWT was verified
The text was updated successfully, but these errors were encountered:
exportdefaultfunctionvalidateExp(exp){constdate=newDate();constnow=Math.round(date.getTime()/1000);// JavaSript dates are accurate to the millisecond but the JWT standard specifies dates accurate to the secondreturnNumber(exp)>now;}
What we did is write a component called ProtectedRoute that either returned a Route or a Redirect depending on whether the user was logged in. If they were logged in it returned the route, otherwise a redirect to the login page. We then put it in our router switch statement whenever we wanted a protected route. The component ended up looking like this:
And our
authorised()
function looked like thisvalidateExp is another one we wrote ourselves. It compares the time in the JWT against the present.
This method doesn't stop a hacker getting to the route. That would require a server request. It just stops a normal user who isnt logged in getting to a route, so it makes routes semi-protected. For us, the specifics, like the cards on the page, required a server request, and there we checked that the JWT was verified
The text was updated successfully, but these errors were encountered: