/nestjs-auth-graphql-starter

NestJS starter template with GraphQL and PassportJS authentication.

Primary LanguageTypeScriptMIT LicenseMIT

Jenyus Logo

Description

Nest framework TypeScript boilerplate with PassportJS authentication, GraphQL and OpenAPI docs integrations.

Note from the Maintainers

This repository has been archived as we consider the use of TypeORM to lead to technical debt in modern web projects. Instead we recommend checking out the MikroORM based starter with an otherwise identical setup.

Setup

  • Uses code-first GraphQL
  • Uses TypeORM for entities and migrations
  • Properly configures ormconfig.js for runtime synchronization and migrations
  • Implements refresh token based auth flow
  • Uses PassportJS and JWT for authentication
  • Custom Prettier and ESLint config
  • Uses @jenyus-org/nestjs-graphql-utils to optimize queries and solve the N+1 problem

Configuration Files

Environment Variables

.env

JWT_KEY=<your-jwt-key-here>

TypeORM

ormconfig.js

const { join } = require("path");

module.exports = {
  type: "sqlite",
  synchronize: true,
  entities: ["dist/**/*.entity.js"],
  database: "tmp/data.sqlite",
  migrations: [join(__dirname, "database", "migrations", "*.ts")],
  cli: {
    migrationsDir: "src/database/migrations",
  },
};

Installation

$ yarn

Running the app

# development
$ yarn start

# watch mode
$ yarn start:dev

# production mode
$ yarn start:prod

Test

# unit tests
$ yarn test

# e2e tests
$ yarn test:e2e

# test coverage
$ yarn test:cov

License

This boilerplate remains true to Nest and is MIT licensed.