Skip to content

Commit

Permalink
Adds testing of public oauth flow (#989)
Browse files Browse the repository at this point in the history
* Adds testing of public oauth flow

* Cleanup test
  • Loading branch information
ericanderson authored Nov 22, 2024
1 parent 4fbacd7 commit d501104
Show file tree
Hide file tree
Showing 4 changed files with 372 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/healthy-news-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@osdk/oauth": patch
---

Adds unit testing of public oauth flow
1 change: 1 addition & 0 deletions packages/monorepo.cspell/dict.test-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ doesnotexist
objectdoesnotexist
Packag
querydoesnotexist
unstub
unstubAllEnvs
interfacers
Claused
Expand Down
14 changes: 8 additions & 6 deletions packages/oauth/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ declare const process: {
env: Record<string, string | undefined>;
};

const localStorage = globalThis.localStorage;

type LocalStorageState =
export type LocalStorageState =
// when we are going to the login page
| {
refresh_token?: never;
Expand Down Expand Up @@ -82,21 +80,25 @@ type LocalStorageState =

export function saveLocal(client: Client, x: LocalStorageState) {
// MUST `localStorage?` as nodejs does not have localStorage
localStorage?.setItem(
globalThis.localStorage?.setItem(
`@osdk/oauth : refresh : ${client.client_id}`,
JSON.stringify(x),
);
}

export function removeLocal(client: Client) {
// MUST `localStorage?` as nodejs does not have localStorage
localStorage?.removeItem(`@osdk/oauth : refresh : ${client.client_id}`);
globalThis.localStorage?.removeItem(
`@osdk/oauth : refresh : ${client.client_id}`,
);
}

export function readLocal(client: Client): LocalStorageState {
return JSON.parse(
// MUST `localStorage?` as nodejs does not have localStorage
localStorage?.getItem(`@osdk/oauth : refresh : ${client.client_id}`)
globalThis.localStorage?.getItem(
`@osdk/oauth : refresh : ${client.client_id}`,
)
?? "{}",
);
}
Expand Down
Loading

0 comments on commit d501104

Please sign in to comment.