Skip to content

Commit

Permalink
feat: add a way to get the refresh token
Browse files Browse the repository at this point in the history
  • Loading branch information
thislooksfun committed Apr 9, 2021
1 parent 7029a16 commit e55b9e2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ export interface ClientOptions {
* ```
*
*
* @example If you already have a refresh token from a previous session you can
* use that as well.
* ```ts
* const client = new Client({
* userAgent: '<your user agent>',
* auth: {
* refreshToken: '<the token>`,
* },
* creds: {
* clientId: '<your client id>',
* clientSecret: '<your client secret>',
* },
* })
* ```
*
*
* @example If you want to make requests not on behalf of a user, you can leave
* out the `auth` key. See {@link ClientOptions.auth} for more details.
* ```ts
Expand All @@ -115,6 +131,7 @@ export interface ClientOptions {
* });
* ```
*
*
* @example If you want to make completely unauthenticated requests, you can
* leave out both the `auth` and `creds` keys. See {@link ClientOptions.creds}
* for more details and restrictions.
Expand Down Expand Up @@ -215,6 +232,17 @@ export default class Client {
await this.updateAccessToken();
}

/**
* Get the refresh token for the current session, if there is one.
*
* This can be stored and later passed to the constructor or {@link reAuth}.
*
* @returns The refresh token, or `null` if no token exists.
*/
getRefreshToken(): String | null {
return this.token?.refresh ?? null;
}

/**
* Perform a GET request to the reddit api.
*
Expand Down

0 comments on commit e55b9e2

Please sign in to comment.