I'm building a react app and want to allow/deny access to some components based (mainly filter IP||MAC) on where the client is.
Any way to restrict routing to deny access to a presentation when the client is connecting from the internet allowing the access when it connects via LAN?
- I think I found an alternative approach, I will maintain the question open looking for alternatives.
- I read that the client should not be able to see its ip address (browser security), and that should be done on the server side (thats a direct approach as mentioned in the above post) (can anyone confirm that).
- The solution is to find the gateway address of the client (normally using NAT) and compare with my gateway address, if equal they are inside LAN.
- I am having a situation that on the computer I am able to see the ip address, on mobile/cellphone I can't, need to investigate.
import React from 'react';
export default () => {
const [addrObj, setAddrObj] = React.useState({});
const fetchAddrData = async () =>
await fetch('http://jsonip.com')
.then(res => res.json())
.then(setAddrObj);
React.useEffect(() => {fetchAddrData()},[])
return (
<>
<h3>Sample Page</h3>
<h4>addr: {addrObj.ip}</h4>
</>
)
}