diff --git a/pages/index.js b/pages/index.js index 93e94ce..83283e2 100644 --- a/pages/index.js +++ b/pages/index.js @@ -30,6 +30,7 @@ export default class Home extends Component { isPreviewVisible: false, previewUrl: undefined, overlayUrl: undefined, + avatarUrl: undefined, values: { socketAddr: undefined, @@ -69,6 +70,7 @@ export default class Home extends Component { }); this.setState({ steamId: json.steamId, values: values }); + this.validateSteamId(json.steamId); } this.setState({ loading: false }); } @@ -121,14 +123,32 @@ export default class Home extends Component { }, 5); } + async validateSteamId(steamId) { + if (steamId.length < 16) { + // Steam ID is invalid + return this.setState({ avatarUrl: undefined }); + } + + const data = await fetch("/api/validateid?steamid=" + steamId); + const json = await data.json(); + + console.log(json); + + if (json.message === "Valid") { + this.setState({ + avatarUrl: `https://cdn.scoresaber.com/avatars/${steamId}.jpg`, + }); + } else { + this.setState({ avatarUrl: undefined }); + } + } + render() { return this.state.loading ? (