Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Last active October 14, 2022 18:16
Show Gist options
  • Save ajcrites/fdcc096c312d4cde1d6acb045ccf3c0e to your computer and use it in GitHub Desktop.
Save ajcrites/fdcc096c312d4cde1d6acb045ccf3c0e to your computer and use it in GitHub Desktop.
export const GAME_FORMAT = '/#{sessionId}/game/format';
@Component(...)
export class ProfilePage {
...
async getGameApp() {
try {
const userId = await this.userService.getUserId();
const userIdToken = userId?.token || '';
this.gameService.formatUserIdToken(userIdToken).subscribe((formattedId) => {
const url = [ENV.GAME_WEB_APP_URL, `formattedId=${formattedId}`].join('?');
Browser.open(url);
});
} catch (err) {
this.errorService.reportError(err);
}
}
}
export class GameService {
...
async formatUserId(userIdToken: String) {
return from(this.http.get(
this.urlBuilder.build(GAME_FORMAT, {
sessionId: this.sessionId,
}, {
queryParams: { userIdToken },
})
)).pipe(
map(({ body: { formattedId } }): FormatUserIdResponse) => formattedId),
throwIfEmpty(() => new Error('Failed to format token'),
catchError((e) => {
return of(e);
})
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment