UNPKG

@twurple/auth

Version:

Authenticate with Twitch and stop caring about refreshing tokens.

51 lines (50 loc) 1.33 kB
import { __decorate } from "tslib"; import { mapNullable } from '@d-fischer/shared-utils'; import { DataObject, rawDataSymbol, rtfm } from '@twurple/common'; /** * Information about an access token. */ let TokenInfo = class TokenInfo extends DataObject { _obtainmentDate; /** @internal */ constructor(data) { super(data); this._obtainmentDate = new Date(); } /** * The client ID. */ get clientId() { return this[rawDataSymbol].client_id; } /** * The ID of the authenticated user. */ get userId() { return this[rawDataSymbol].user_id ?? null; } /** * The name of the authenticated user. */ get userName() { return this[rawDataSymbol].login ?? null; } /** * The scopes for which the token is valid. */ get scopes() { return this[rawDataSymbol].scopes; } /** * The time when the token will expire. * * If this returns null, it means that the token never expires (happens with some old client IDs). */ get expiryDate() { return mapNullable(this[rawDataSymbol].expires_in, v => new Date(this._obtainmentDate.getTime() + v * 1000)); } }; TokenInfo = __decorate([ rtfm('auth', 'TokenInfo', 'clientId') ], TokenInfo); export { TokenInfo };