Encapsulation method

import axios from 'axios'
const allowIP = ['119.133.5.19']; // Allow access to the whitelist
async function getIp() {
    const res=await axios.get('https://api.ipify.org/')// This interface can be found on the network, as long as it is allowed to cross domain
    return res.data
}

async function isAllow(){
    let isAllow=false
    let ip=await getIp()
    for(let i=0; i<allowIP.length; i++){
        if (ip == allowIP[i]){
            isAllow=true
            break; }}return isAllow
}
export default isAllow
Copy the code

use

import isAllow from './utils/isAllow.js'
const ISALLOW=await isAllow()
if(ISALLOW){
  console.log('Whitelist')}else{
  console.log('Access not allowed')}Copy the code