Redwoodjs V4 - Auth Decoder

This codemod for RedwoodJS v4 automatically inserts an authDecoder property into the createGraphQLHandler call.

RedwoodJS
jscodeshift
Estimated time saving
~6 minutes/occurrence
Change mode
Assistive
Applicability criteria

RedwoodJS < v4.0.0

Made by
Rajasegar Chandran
Rajasegar Chandran

Usage →

Codemod CLI:

intalling vs code extension tooltip icon
codemod redwoodjs/core/4/auth-decoder
copy CLI command icon

Codemod VS Code extension:

intalling vs code extension tooltip icon
vs code logo
Run in VS Code

Use/edit codemod in Codemod Studio:

intuita logo without text
Open in Codemod Studio

Auth Decoder

Description

This codemod for RedwoodJS v4 automatically inserts an authDecoder property into the createGraphQLHandler call if it's not already present. It also adds an import statement for authDecoder from @redwoodjs/auth-auth0-api at the beginning of the file, ensuring that the necessary functionality for authentication is correctly integrated.

Example

Before

import { createGraphQLHandler } from '@redwoodjs/graphql-server';

import directives from 'src/directives/**/*.{js,ts}';
import sdls from 'src/graphql/**/*.sdl.{js,ts}';
import services from 'src/services/**/*.{js,ts}';

import { db } from 'src/lib/db';
import { logger } from 'src/lib/logger';

export const handler = createGraphQLHandler({
  loggerConfig: { logger, options: {} },
  directives,
  sdls,
  services,
  onException: () => {
    // Disconnect from your database with an unhandled exception.
    db.$disconnect();
  },
});

After

import { authDecoder } from '@redwoodjs/auth-auth0-api';
import { createGraphQLHandler } from '@redwoodjs/graphql-server';

import directives from 'src/directives/**/*.{js,ts}';
import sdls from 'src/graphql/**/*.sdl.{js,ts}';
import services from 'src/services/**/*.{js,ts}';

import { db } from 'src/lib/db';
import { logger } from 'src/lib/logger';

export const handler = createGraphQLHandler({
  authDecoder: authDecoder,
  loggerConfig: { logger, options: {} },
  directives,
  sdls,
  services,

  onException: () => {
    // Disconnect from your database with an unhandled exception.
    db.$disconnect();
  }
});