web-auth
web-auth copied to clipboard
[Bug]: incomplete condition to check for localhost network
Thanks a ton for the workshop material! I've had a great time digging into the intricacies of web auth.
I noticed a small issue while working on the Verification Module, Generate TOTP step (11/02). If I run my app on the local network (e.g., http://192.168.xxx.xxx:port) and use the getDomainUrl util, the raw IP address does not pass the localhost condition. Because of that, the https protocol is appended instead of http, which leads to a ERR_SSL_PROTOCOL_ERROR when I redirect to the /verify page.
I was able to get around this by extending the condition, though this makes the utility slightly more complicated:
- const protocol = host.includes('localhost') ? 'http' : 'https'
+ const isLocalHost = host.includes('localhost') || /^192\.168\.\d{1,3}\.\d{1,3}/.test(host)
+ const protocol = isLocalHost ? 'http' : 'https'