Location-Based Access Control Made Easy with Next.js and IPInfo

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • demo-projects

  • Learn more about Permit or IPInfo — or access the whole code repository for this project here.

  • cli

    Official Command Line Interface for the IPinfo API (IP geolocation and other types of IP data) (by ipinfo)

  • import { Permit } from "permitio"; const permit = new Permit({ pdp: "http://localhost:7766", // your API Key token: process.env.PERMIT_API_KEY, }); const fetchLocationByIP = async () => { const request = await fetch( `https://ipinfo.io/json?token=${process.env.IP_INFO_TOKEN}` ); const jsonResponse = await request.json(); console.log(jsonResponse.ip, jsonResponse.country); return jsonResponse.country; }; export default async function enforceAccess(req, res) { // Getting the country code and storing in a variable const IPlocation = await fetchLocationByIP(); const allowed = await permit.check( { key: "[email protected]", attributes: { // Passing the variable to the ip_location attribute ip_location: IPlocation, }, }, "view", { type: "only-uk", tenant: "default", } ); res.status(200).send({ allowed }); return allowed; }

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
  • react-native-auth0

    React Native toolkit for Auth0 API

  • If you would like to check out a guide on how to add a user to Permit after successful authentication with Auth0, check out the article here.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts