IP 位置
访问应用程序中的IP地理位置数据
SuperStarter使用Arcjet进行应用安全防护,其中包含您可以在应用程序中使用的IP详情和地理位置信息。
在app
应用中,Arcjet在apps/app/app/(authenticated)/layout.tsx
文件中被调用,该文件在每个认证路由上运行。
对于web
应用,Arcjet在中间件中被调用,该中间件在每个请求上运行(静态资源除外)。
在这两种情况下,您都可以基于IP详情应用应用/网站范围的规则,例如根据用户位置显示不同内容。
访问IP位置数据
IP详情可在Arcjet决策对象中获得,该对象从aj.protect()
调用返回。IP位置字段可能为undefined
,因此您可以使用各种实用函数来获取数据。
See the Arcjet IP analysis reference for more information on the fields available.
在其他地方访问IP详情
Next.js不允许从根布局或中间件传递数据到应用程序的其他页面。要在应用程序的其他部分访问IP详情,您需要从根布局(app
)或中间件(web
)中移除Arcjet调用,并在需要IP详情的特定页面中调用它。
请参阅Arcjet文档了解如何在路由处理器、页面/服务器组件和服务器操作中调用aj.protect()
。
If you remove the Arcjet call from apps/app/app/(authenticated)/layout.tsx
or middleware.ts
it will no longer run on every request. You will need to call aj.protect()
everywhere you wish to apply Arcjet rules, even if you don’t need the IP details.