fix: 🐛 signin with ipv6

co-authored-by: Syuilo
This commit is contained in:
ThatOneCalculator 2023-01-24 15:13:25 -08:00
parent 970b4907f3
commit 95595dafcb
No known key found for this signature in database
GPG Key ID: 8703CACD01000000
1 changed files with 10 additions and 5 deletions

View File

@ -1,9 +1,14 @@
import IPCIDR from "ip-cidr";
export function getIpHash(ip: string) {
// because a single person may control many IPv6 addresses,
// only a /64 subnet prefix of any IP will be taken into account.
// (this means for IPv4 the entire address is used)
const prefix = IPCIDR.createAddress(ip).mask(64);
return `ip-${BigInt(`0b${prefix}`).toString(36)}`;
try {
// because a single person may control many IPv6 addresses,
// only a /64 subnet prefix of any IP will be taken into account.
// (this means for IPv4 the entire address is used)
const prefix = IPCIDR.createAddress(ip).mask(64);
return `ip-${BigInt(`0b${prefix}`).toString(36)}`;
} catch (e) {
const prefix = IPCIDR.createAddress(ip.replace(/:[0-9]+$/, "")).mask(64);
return `ip-${BigInt(`0b${prefix}`).toString(36)}`;
}
}