Skip to content

Commit

Permalink
chore(release) (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgoff authored Sep 5, 2024
1 parent 4628210 commit c35be81
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 17 deletions.
8 changes: 4 additions & 4 deletions components/auth/serverHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ export async function getAuthCookies() {
}

export function deleteAuthCookies() {
cookies().set("craftToken", "", COOKIE_OPTIONS);
cookies().set("craftRefreshToken", "", COOKIE_OPTIONS);
cookies().set("craftUserStatus", "", COOKIE_OPTIONS);
cookies().set("craftUserId", "", COOKIE_OPTIONS);
cookies().delete("craftToken");
cookies().delete("craftRefreshToken");
cookies().delete("craftUserStatus");
cookies().delete("craftUserId");
}

export function getUserFromJwt(jwt?: Token) {
Expand Down
9 changes: 0 additions & 9 deletions components/molecules/auth/SignOutButton/actions.ts

This file was deleted.

2 changes: 1 addition & 1 deletion components/molecules/auth/SignOutButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useTranslation } from "react-i18next";
import Button from "@rubin-epo/epo-react-lib/Button";
import { signOut } from "./actions";
import signOut from "@/lib/api/auth/actions/signOut";

export default function SignOut({ redirectTo }: { redirectTo: string }) {
const { t } = useTranslation();
Expand Down
8 changes: 6 additions & 2 deletions components/page/Menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useTranslation } from "react-i18next";
import { useGlobalData } from "@/hooks";
import usePages from "@/contexts/Pages";
import { useAuthDialogManager } from "@/contexts/AuthDialogManager";
import { signOut } from "@/components/molecules/auth/SignOutButton/actions";
import signOut from "@/lib/api/auth/actions/signOut";
import Language from "./submenu/Language";
import Acknowledgements from "./submenu/Acknowledgements";
import Share from "./submenu/Share";
Expand Down Expand Up @@ -79,7 +79,11 @@ const Menu: FunctionComponent<MenuProps> = ({
<MenuItem
icon="LogOut"
text={t("auth.log_out")}
onClick={handleLogout}
onClick={() => {
handleLogout().finally(() => {
localStorage.clear();
});
}}
/>
) : (
<MenuItem
Expand Down
5 changes: 5 additions & 0 deletions gql/public-schema/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const documents = {
"fragment UserFragment on UserInterface {\n id\n status\n}": types.UserFragmentFragmentDoc,
"\n mutation ResendActivation($email: String!) {\n resendActivation(email: $email)\n }\n": types.ResendActivationDocument,
"\n mutation Authenticate($email: String!, $password: String!) {\n authenticate(email: $email, password: $password) {\n ...AuthFragment\n }\n }\n": types.AuthenticateDocument,
"\n mutation DeleteRefreshToken($refreshToken: String!) {\n deleteRefreshToken(refreshToken: $refreshToken)\n }\n": types.DeleteRefreshTokenDocument,
};

/**
Expand Down Expand Up @@ -379,6 +380,10 @@ export function graphql(source: "\n mutation ResendActivation($email: String!)
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n mutation Authenticate($email: String!, $password: String!) {\n authenticate(email: $email, password: $password) {\n ...AuthFragment\n }\n }\n"): (typeof documents)["\n mutation Authenticate($email: String!, $password: String!) {\n authenticate(email: $email, password: $password) {\n ...AuthFragment\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n mutation DeleteRefreshToken($refreshToken: String!) {\n deleteRefreshToken(refreshToken: $refreshToken)\n }\n"): (typeof documents)["\n mutation DeleteRefreshToken($refreshToken: String!) {\n deleteRefreshToken(refreshToken: $refreshToken)\n }\n"];

export function graphql(source: string) {
return (documents as any)[source] ?? {};
Expand Down
10 changes: 9 additions & 1 deletion gql/public-schema/graphql.ts

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions lib/api/auth/actions/signOut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"use server";

import { redirect } from "next/navigation";
import { graphql } from "@/gql/public-schema";
import {
deleteAuthCookies,
getAuthCookies,
} from "@/components/auth/serverHelpers";
import { mutateAPI } from "@/lib/fetch";

const Mutation = graphql(`
mutation DeleteRefreshToken($refreshToken: String!) {
deleteRefreshToken(refreshToken: $refreshToken)
}
`);

async function signOut(redirectTo: string) {
const { craftRefreshToken, craftToken } = await getAuthCookies();

if (craftRefreshToken && craftToken) {
await mutateAPI({
query: Mutation,
variables: {
refreshToken: craftRefreshToken,
},
token: craftToken,
});
}

deleteAuthCookies();
redirect(redirectTo);
}

export default signOut;

0 comments on commit c35be81

Please sign in to comment.