Skip to content

Commit

Permalink
Update login with toke
Browse files Browse the repository at this point in the history
  • Loading branch information
NolanTrem committed Sep 25, 2024
1 parent c8d8547 commit 6cf898b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions js/sdk/src/models.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface TokenInfo {
token: string;
token_type: string;
}

export interface LoginResponse {
Expand Down
21 changes: 21 additions & 0 deletions js/sdk/src/r2rClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,27 @@ export class r2rClient {
return response.results;
}

@feature("loginWithToken")
async loginWithToken(
accessToken: string,
): Promise<{ access_token: TokenInfo }> {
this.accessToken = accessToken;

try {
await this._makeRequest("GET", "user");

return {
access_token: {
token: accessToken,
token_type: "access_token",
},
};
} catch (error) {
this.accessToken = null;
throw new Error("Invalid token provided");
}
}

/**
* Logs out the currently authenticated user.
* @returns A promise that resolves to the response from the server.
Expand Down

0 comments on commit 6cf898b

Please sign in to comment.