Skip to content

Commit

Permalink
fix(gatsby-oauth): accessToken with executor
Browse files Browse the repository at this point in the history
  • Loading branch information
colorfield committed Apr 15, 2024
1 parent 8eb7ae8 commit 7d2893c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
9 changes: 6 additions & 3 deletions apps/website/src/templates/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ import { drupalExecutor } from '../utils/drupal-executor';

export default function ProfilePage() {
const session = useSession();
let accessToken = null;
let accessToken: string | undefined = undefined;
if (session && session.status === 'authenticated') {
// @ts-ignore
accessToken = session.data.user.tokens.access_token;
const authenticatedExecutor = drupalExecutor(
`${process.env.GATSBY_DRUPAL_URL}/graphql`,
false,
accessToken,
);
return (
<OperationExecutor
executor={async () => {
const data = await authenticatedExecutor(CurrentUserQuery, {});
const data = await authenticatedExecutor(
CurrentUserQuery,
{},
accessToken,
);
return {
currentUser: data.currentUser,
};
Expand Down
7 changes: 2 additions & 5 deletions apps/website/src/utils/drupal-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import { AnyOperationId, OperationVariables } from '@custom/schema';
/**
* Create an executor that operates against a Drupal endpoint.
*/
export function drupalExecutor(
endpoint: string,
forward: boolean = true,
accessToken: string | undefined = undefined,
) {
export function drupalExecutor(endpoint: string, forward: boolean = true) {
return async function <OperationId extends AnyOperationId>(
id: OperationId,
variables?: OperationVariables<OperationId>,
accessToken?: string,
) {
const url = new URL(endpoint, window.location.origin);
const isMutation = id.includes('Mutation:');
Expand Down
3 changes: 1 addition & 2 deletions packages/schema/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ export function OperationExecutor<OperationId extends AnyOperationId>(
export function useExecutor<OperationId extends AnyOperationId>(
id: OperationId,
variables?: OperationVariables<OperationId>,
accessToken?: string,
):
| OperationResult<OperationId>
| ((
variables?: OperationVariables<OperationId>,
) => Promise<OperationResult<OperationId>>) {
return untypedUseExecutor(id, variables, accessToken);
return untypedUseExecutor(id, variables);
}

0 comments on commit 7d2893c

Please sign in to comment.