-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Bridge Handler for Fetching Logged in Steam User
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {SimpleHandler} from './main'; | ||
import {RequestType} from './types'; | ||
|
||
interface FetchSteamUserRequest {} | ||
|
||
interface FetchSteamUserResponse { | ||
isLoggedIn: boolean; | ||
steamID?: string; | ||
sessionID?: string; | ||
} | ||
|
||
export const FetchSteamUser = new SimpleHandler<FetchSteamUserRequest, FetchSteamUserResponse>( | ||
RequestType.FETCH_STEAM_USER, | ||
async (req) => { | ||
const resp = await fetch('https://steamcommunity.com'); | ||
if (!resp.ok) { | ||
throw new Error('non-ok response for steamcommunity.com'); | ||
} | ||
|
||
const res: FetchSteamUserResponse = { | ||
isLoggedIn: false, | ||
}; | ||
|
||
const text = await resp.text(); | ||
const steamIDMatch = text.match(/g_steamID = "(\d+)"/); | ||
if (steamIDMatch) { | ||
res.isLoggedIn = true; | ||
res.steamID = steamIDMatch[1]; | ||
} | ||
|
||
const sessionIDMatch = text.match(/g_sessionID = "([0-9a-fA-F]+)"/); | ||
if (sessionIDMatch) { | ||
res.sessionID = sessionIDMatch[1]; | ||
} | ||
|
||
return res; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters