Apply security controls at the UI/component level and ensure input validation is centralized.
1) Auth-state gating (authorization/flow correctness)
export function SubscribeToChangelog({ isLoggedIn }: { isLoggedIn: boolean }) {
if (isLoggedIn) return null; // or an alternative message
return <button onClick={/* show subscribe flow */}>Subscribe</button>;
}
2) Centralize validation rules (input validation consistency)
.test(value), orconst USERNAME_REGEX = /^[a-zA-Z0-9]{0,20}$/; // includes length constraint
export function isUsernameValid(value: string) {
return USERNAME_REGEX.test(value);
}
// usage
const isValid = isUsernameValid(value);
This prevents unauthorized/incorrect flows from appearing to the user and reduces the risk of inconsistent validation logic across the codebase.
Enter the URL of a public GitHub repository