0.7.0 • Published 7 months ago

@kagari/auth v0.7.0

Weekly downloads
-
License
-
Repository
github
Last release
7 months ago

@kagari/auth

A facility for authentication based on passport & typeorm, supports session and jwt

Usage

prepare business logic

// validation function
import { ComposeAccessTokenPayload, ComposeRefreshTokenPayload, ValidateFunction } from '@kagari/auth';
import { UserEntity } from './User.entity';

// validate credential
export const validate: ValidateFunction = (credential) => {
  // any logic validate if input is valid
  return credential // return validated values
}

// verify crendetial
export const verify: ValidateFunction = async (repo, credential) => {
  // your logic verify the user(if password matches)
  return { id: 1, username: 'foobar' }
}

// token genderators
export const getAccessTokenPayload: ComposeAccessTokenPayload = (userInfo) => (userInfo)
export const getRefreshTokenPayload: ComposeRefreshTokenPayload = (userInfo) => (userInfo)

register modules

// local session
import { JwtAuthModule, LocalAuthModule } from '@kagari/auth';
import { UserEntity } from './User.entity';
import { composeAccessTokenPayload, composeRefreshTokenPayload } from './helpers';


// or use forRoot directly
LocalAuthModule.forRootAsync({
  useFactory: () => ({
    entity: UserEntity,
    validate: validate,
    verfiy: verify,
    session: {
      // options for express-session
    },
    include: [
      // options for MiddlewareConsumer.forRoutes()
      // for all by default
    ],
    exclude: [
      // options for MiddlewareConsumer.forRoutes().exclude()
      // exclude `/api/**` by default
    ],
  })
})

// or use forRoot directly
JwtAuthModule.forRootAsync({
  useFactory: () => ({
    entity: UserEntity,
    validate: validate,
    verify: verify,
    jwt: {
      // options for @nestjs/jwt module
    },
    payload: {
      access: composeAccessTokenPayload,
      refresh: composeRefreshTokenPayload,
    }
  })
})
0.6.2

9 months ago

0.6.4

7 months ago

0.7.0

7 months ago

0.5.10

12 months ago

0.5.11

12 months ago

0.6.1

12 months ago

0.4.9

1 year ago

0.4.8

1 year ago

0.5.4

1 year ago

0.5.2

1 year ago

0.2.1

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.12

1 year ago

0.3.1

1 year ago

0.1.0

2 years ago

0.0.4

2 years ago