mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
Enhances sign-up process with Turnstile integration for fraud protection. Builds on top of fraud-protection-temp-emails. Made with [Cursor](https://cursor.com) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Cloudflare Turnstile bot-protection across signup/sign-in flows (including SDK JSON mode). * Email deliverability checks via Emailable. * Sign-up risk scoring with persisted risk metrics and country code tracking. * UI: country-code selector, risk-score editing in user details, users list refresh button, and Turnstile signup demo pages. * **Bug Fixes** * Use actual sign-up timestamp for reporting/metrics. * **Documentation** * Expanded knowledge base on Turnstile, risk scoring, and env configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Konstantin Wohlwend <n2d4xc@gmail.com> Co-authored-by: BilalG1 <bg2002@gmail.com> Co-authored-by: Armaan Jain <84474476+Developing-Gamer@users.noreply.github.com> Co-authored-by: nams1570 <amanganapathy@gmail.com>
25 lines
1.2 KiB
TypeScript
25 lines
1.2 KiB
TypeScript
import { isValidCountryCode, normalizeCountryCode } from "./country-codes";
|
|
import { StackAssertionError } from "./errors";
|
|
|
|
export function getFlagEmoji(twoLetterCountryCode: string) {
|
|
if (!isValidCountryCode(twoLetterCountryCode)) throw new StackAssertionError("Country code must be two alphabetical letters");
|
|
const codePoints = normalizeCountryCode(twoLetterCountryCode)
|
|
.split('')
|
|
.map(char => 127397 + char.charCodeAt(0));
|
|
return String.fromCodePoint(...codePoints);
|
|
}
|
|
import.meta.vitest?.test("getFlagEmoji", ({ expect }) => {
|
|
// Test with valid country codes
|
|
expect(getFlagEmoji("US")).toBe("🇺🇸");
|
|
expect(getFlagEmoji("us")).toBe("🇺🇸");
|
|
expect(getFlagEmoji("GB")).toBe("🇬🇧");
|
|
expect(getFlagEmoji("JP")).toBe("🇯🇵");
|
|
|
|
// Test with invalid country codes
|
|
expect(() => getFlagEmoji("")).toThrow("Country code must be two alphabetical letters");
|
|
expect(() => getFlagEmoji("A")).toThrow("Country code must be two alphabetical letters");
|
|
expect(() => getFlagEmoji("ABC")).toThrow("Country code must be two alphabetical letters");
|
|
expect(() => getFlagEmoji("12")).toThrow("Country code must be two alphabetical letters");
|
|
expect(() => getFlagEmoji("A1")).toThrow("Country code must be two alphabetical letters");
|
|
});
|