How can I make a button show up when logging in from an specific IP adress?

274 Views Asked by At

So I'm working on this extremely basic and minimalistic social media platform called NetEdit. I have currently set up a button there that will clear all posts, but its commented, so I can uncomment it and use it whenever I want to reset the site. The problem is, I want to make it show up only when I log in via my IP adress to make the process more fluid. I have little to no experience with JavaScript or CSS, so I'm very confused. Can anyone help?

The link to the code is https://glitch.com/edit/#!/netedit

1

There are 1 best solutions below

0
On

IP addresses don't change very often but sometimes they change. I'd recommend you to use a different type of authentication like a passcode (password, number, ...etc)

  1. if you decide to use Authentication, you could create a private Login page, where you enter your password.

  2. Having said the above either way, you would need #if-condition, to check if it is you and make that button visible.

const ProvidedIP = "48.168.70.20";
const AdminIP = "50.162.68.2";
let showButton = false;

if(Provided === AdminIP){
   showButton = true;
}

// get the button
document.querySelector("#buttonID").style.display = showButton ? "initial" : "non#"