UNPKG

rauth-client

Version:

A lightweight, framework-agnostic JavaScript/TypeScript library for adding reverse authentication via WhatsApp on the client side.

3 lines (2 loc) 2.21 kB
const n={async init({appId:n,phone:e}){if(!n||!e)throw new Error("appId and phone are required");const o=await async function(){const n="undefined"!=typeof navigator?navigator:void 0;if(n&&n.userAgentData&&Array.isArray(n.userAgentData.brands)){const e=function(n){const e=["brave","edge","chrome","firefox","safari","opera"];for(const o of n){const n=o.brand.toLowerCase();for(const o of e)if(n.includes(o))return o}return""}(n.userAgentData.brands);if(e){let o=n.userAgentData.platform?n.userAgentData.platform.toLowerCase():"";return"windows"!==o&&"Windows"!==n.userAgentData.platform||(o="windows 10"),{browser:e,platform:o,session_source:"website"}}}const e="undefined"!=typeof navigator?navigator.userAgent:"",o=function(n){return(n=n.toLowerCase()).includes("edg/")?"edge":n.includes("chrome")&&!n.includes("edg/")?"chrome":n.includes("firefox")?"firefox":n.includes("safari")&&!n.includes("chrome")?"safari":n.includes("opera")||n.includes("opr/")?"opera":"unknown"}(e),t=function(n){return(n=n.toLowerCase()).includes("windows nt 10.0")?"windows 10":n.includes("windows nt 11.0")?"windows 11":n.includes("android")?"android":n.includes("iphone")||n.includes("ipad")?"ios":n.includes("mac os x")?"macos":n.includes("linux")?"linux":"unknown"}(e);return{browser:o,platform:t,session_source:"website"}}(),{ip:t,location:r}=await async function(){try{const n=await fetch("https://free.freeipapi.com/api/json"),e=await n.json();return{ip:e.ipAddress||"",city:e.cityName||"",country:e.countryName||"",location:e.cityName&&e.countryName?`${e.cityName}, ${e.countryName}`:""}}catch{return{ip:"",city:"",country:"",location:""}}}(),a={phone:e,ip:t,location:r,browser:o.browser,platform:o.platform,session_source:o.session_source};"undefined"!=typeof navigator&&navigator.platform&&""!==navigator.platform&&(a.device_name=navigator.platform);const i=await fetch("https://api.rauth.io/session/init",{method:"POST",headers:{"Content-Type":"application/json","x-app-id":n},body:JSON.stringify(a)});if(!i.ok){const n=await i.text();throw new Error("Rauth API error: "+n)}return i.json()}};"undefined"!=typeof window&&(window.rauth=n);export{n as default,n as rauth}; //# sourceMappingURL=rauth-client.esm.js.map