mirror of
https://github.com/wassname/talk.git
synced 2026-08-06 13:41:02 +08:00
[next] Email (#2261)
* feat: suspending, banning, now propogation * feat: added email rendering + localization support * fix: fix related to lib * refactor: moved juicer to queue task * refactor: cleanup of job processor * refactor: improved error messaging around failed email * feat: initial forgot passwor impl * fix: fixed rebase errors * feat: send back Content-Language header with requests * feat: added ban email * feat: implemented forgotten password API * fix: linting * feat: support more emails * fix: promise patches * feat: initial confirm email API * feat: added rate limiting * feat: added URL support * feat: added email docs * fix: updated docs * chore: documentation review * fix: fixed build bug * feat: implement forgot password in auth popup * test: add tests + fixes * chore: rename StatelessComponent to FunctionComponent * fix: types and test fixes * chore: upgrade deps * fix: THANK YOU TESTS FOR SAVING MY A** * chore: reorder imports * chore: remove obsolete ! * feat: implement accounts bundle * refactor: review suggestion * fix: rebase upgrade error * fix: rebase bug * feat: reset password link support * test: add tests for account password reset page * fix: remove redirect uri * fix: revert local state changes
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
createRelayEnvironment,
|
||||
} from "talk-framework/testHelpers";
|
||||
|
||||
import { commit } from "./SetAccessTokenMutation";
|
||||
import SetAccessTokenMutation from "./SetAccessTokenMutation";
|
||||
|
||||
let environment: Environment;
|
||||
const source: RecordSource = new RecordSource();
|
||||
@@ -28,7 +28,11 @@ it("Sets auth token to localStorage", async () => {
|
||||
localStorage: createPromisifiedStorage(),
|
||||
clearSession: clearSessionStub,
|
||||
};
|
||||
await commit(environment, { accessToken }, context as any);
|
||||
await SetAccessTokenMutation.commit(
|
||||
environment,
|
||||
{ accessToken },
|
||||
context as any
|
||||
);
|
||||
expect(source.get(LOCAL_ID)!.accessToken).toEqual(accessToken);
|
||||
await expect(context.localStorage!.getItem("accessToken")).resolves.toEqual(
|
||||
accessToken
|
||||
@@ -43,7 +47,11 @@ it("Removes auth token from localStorage", async () => {
|
||||
clearSession: clearSessionStub,
|
||||
};
|
||||
localStorage.setItem("accessToken", accessToken);
|
||||
await commit(environment, { accessToken: null }, context as any);
|
||||
await SetAccessTokenMutation.commit(
|
||||
environment,
|
||||
{ accessToken: null },
|
||||
context as any
|
||||
);
|
||||
await expect(
|
||||
context.localStorage!.getItem("accessToken")
|
||||
).resolves.toBeNull();
|
||||
|
||||
@@ -3,36 +3,32 @@ import { Environment } from "relay-runtime";
|
||||
import { TalkContext } from "talk-framework/lib/bootstrap";
|
||||
import {
|
||||
commitLocalUpdatePromisified,
|
||||
createMutationContainer,
|
||||
createMutation,
|
||||
setAccessTokenInLocalState,
|
||||
} from "talk-framework/lib/relay";
|
||||
|
||||
export interface SetAccessTokenInput {
|
||||
interface SetAccessTokenInput {
|
||||
accessToken: string | null;
|
||||
}
|
||||
|
||||
export type SetAccessTokenMutation = (
|
||||
input: SetAccessTokenInput
|
||||
) => Promise<void>;
|
||||
|
||||
export async function commit(
|
||||
environment: Environment,
|
||||
input: SetAccessTokenInput,
|
||||
{ localStorage, clearSession }: TalkContext
|
||||
) {
|
||||
await commitLocalUpdatePromisified(environment, async store => {
|
||||
setAccessTokenInLocalState(input.accessToken, store);
|
||||
if (input.accessToken) {
|
||||
await localStorage.setItem("accessToken", input.accessToken);
|
||||
} else {
|
||||
await localStorage.removeItem("accessToken");
|
||||
}
|
||||
// Clear current session, as we are starting a new one.
|
||||
await clearSession();
|
||||
});
|
||||
}
|
||||
|
||||
export const withSetAccessTokenMutation = createMutationContainer(
|
||||
const SetAccessTokenMutation = createMutation(
|
||||
"setAccessToken",
|
||||
commit
|
||||
async (
|
||||
environment: Environment,
|
||||
input: SetAccessTokenInput,
|
||||
{ localStorage, clearSession }: TalkContext
|
||||
) => {
|
||||
await commitLocalUpdatePromisified(environment, async store => {
|
||||
setAccessTokenInLocalState(input.accessToken, store);
|
||||
if (input.accessToken) {
|
||||
await localStorage.setItem("accessToken", input.accessToken);
|
||||
} else {
|
||||
await localStorage.removeItem("accessToken");
|
||||
}
|
||||
// Clear current session, as we are starting a new one.
|
||||
await clearSession();
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export default SetAccessTokenMutation;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Environment } from "relay-runtime";
|
||||
import { TalkContext } from "talk-framework/lib/bootstrap";
|
||||
import { createMutationContainer } from "talk-framework/lib/relay";
|
||||
import signOut from "../rest/signOut";
|
||||
import { commit as setAccessToken } from "./SetAccessTokenMutation";
|
||||
import SetAccessTokenMutation from "./SetAccessTokenMutation";
|
||||
|
||||
export type SignOutMutation = () => Promise<void>;
|
||||
|
||||
@@ -12,7 +12,7 @@ export async function commit(
|
||||
ctx: TalkContext
|
||||
) {
|
||||
await signOut(ctx.rest);
|
||||
await setAccessToken(environment, { accessToken: "" }, ctx);
|
||||
await SetAccessTokenMutation.commit(environment, { accessToken: "" }, ctx);
|
||||
}
|
||||
|
||||
export const withSignOutMutation = createMutationContainer("signOut", commit);
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
export {
|
||||
withSetAccessTokenMutation,
|
||||
SetAccessTokenMutation,
|
||||
SetAccessTokenInput,
|
||||
} from "./SetAccessTokenMutation";
|
||||
export { default as SetAccessTokenMutation } from "./SetAccessTokenMutation";
|
||||
export { withSignOutMutation, SignOutMutation } from "./SignOutMutation";
|
||||
export {
|
||||
withSetNetworkStatusMutation,
|
||||
|
||||
Reference in New Issue
Block a user