mirror of
https://github.com/wassname/talk.git
synced 2026-09-11 12:51:33 +08:00
Full PromisifiedStorage + Simplifications
This commit is contained in:
@@ -33,24 +33,3 @@ it("Removes auth token from localStorage", () => {
|
||||
commit(environment, { authToken: null }, context as any);
|
||||
expect(context.localStorage.getItem("authToken")).toBeNull();
|
||||
});
|
||||
|
||||
it("Sets auth token to pymLocalStorage", async () => {
|
||||
const context = {
|
||||
pymLocalStorage: createInMemoryStorage(),
|
||||
localStorage: createInMemoryStorage(),
|
||||
};
|
||||
const authToken = "auth token";
|
||||
commit(environment, { authToken }, context as any);
|
||||
expect(source.get(LOCAL_ID)!.authToken).toEqual(authToken);
|
||||
expect(await context.pymLocalStorage.getItem("authToken")).toEqual(authToken);
|
||||
});
|
||||
|
||||
it("Removes auth token from pymLocalStorage", async () => {
|
||||
const context = {
|
||||
pymLocalStorage: createInMemoryStorage(),
|
||||
localStorage: createInMemoryStorage(),
|
||||
};
|
||||
localStorage.setItem("authToken", "tmp");
|
||||
commit(environment, { authToken: null }, context as any);
|
||||
expect(await context.pymLocalStorage.getItem("authToken")).toBeNull();
|
||||
});
|
||||
|
||||
@@ -13,16 +13,15 @@ export type SetAuthTokenMutation = (input: SetAuthTokenInput) => Promise<void>;
|
||||
export async function commit(
|
||||
environment: Environment,
|
||||
input: SetAuthTokenInput,
|
||||
{ localStorage, pymLocalStorage }: TalkContext
|
||||
{ localStorage }: TalkContext
|
||||
) {
|
||||
return commitLocalUpdate(environment, store => {
|
||||
const record = store.get(LOCAL_ID)!;
|
||||
record.setValue(input.authToken, "authToken");
|
||||
const storage = pymLocalStorage || localStorage;
|
||||
if (input.authToken) {
|
||||
storage.setItem("authToken", input.authToken);
|
||||
localStorage.setItem("authToken", input.authToken);
|
||||
} else {
|
||||
storage.removeItem("authToken");
|
||||
localStorage.removeItem("authToken");
|
||||
}
|
||||
// Increment auth revision to indicate a change in auth state.
|
||||
record.setValue(record.getValue("authRevision") + 1, "authRevision");
|
||||
|
||||
Reference in New Issue
Block a user