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 413437f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 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

0 comments on commit 413437f

Please sign in to comment.