Skip to content

Commit

Permalink
feat: add support for auth providers
Browse files Browse the repository at this point in the history
  • Loading branch information
dziraf committed Nov 21, 2023
1 parent 9fff69f commit 0793726
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 76 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
"peerDependencies": {
"@nestjs/common": ">=9.0.5",
"@nestjs/core": ">=9.0.5",
"adminjs": "^7.0.0",
"adminjs": "^7.4.0",
"rxjs": "^7.1.0"
},
"devDependencies": {
"@adminjs/express": "^6.0.0",
"@adminjs/express": "^6.1.0",
"@commitlint/cli": "^17.4.4",
"@commitlint/config-conventional": "^17.4.4",
"@nestjs/common": ">=9.3.10",
"@nestjs/core": ">=9.3.10",
"@semantic-release/git": "^10.0.1",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"adminjs": "^7.0.0",
"adminjs": "^7.4.0",
"eslint": "^8.36.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.27.5",
Expand Down
2 changes: 1 addition & 1 deletion src/admin-resource.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DynamicModule, Module } from '@nestjs/common';
import { ResourceWithOptions } from 'adminjs';
import { type ResourceWithOptions } from 'adminjs';

import AdminResourceService from './admin-resource.service.js';

Expand Down
2 changes: 1 addition & 1 deletion src/admin-resource.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common';
import { ResourceWithOptions } from 'adminjs';
import { type ResourceWithOptions } from 'adminjs';

@Injectable()
class AdminResourceService {
Expand Down
5 changes: 3 additions & 2 deletions src/admin.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DynamicModule, Inject, Module, OnModuleInit } from '@nestjs/common'
import { HttpAdapterHost } from '@nestjs/core'
import AdminJS from 'adminjs'

import AdminResourceService from './admin-resource.service.js'
import { AdminModuleFactory } from './interfaces/admin-module-factory.interface.js'
Expand Down Expand Up @@ -122,11 +121,13 @@ export class AdminModule implements OnModuleInit {
/**
* Applies given options to AdminJS and initializes it
*/
public onModuleInit() {
public async onModuleInit() {
if ('shouldBeInitialized' in this.adminModuleOptions && !this.adminModuleOptions.shouldBeInitialized) {
return;
}

const { default: AdminJS } = await import('adminjs');

const forFeatureResources = AdminResourceService.getResources()

const adminJSOptions = forFeatureResources.length > 0
Expand Down
5 changes: 3 additions & 2 deletions src/interfaces/admin-module-options.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AdminJSOptions, CurrentAdmin } from 'adminjs';
import type { AdminJSOptions, BaseAuthProvider, CurrentAdmin } from 'adminjs';
import { SessionOptions } from 'express-session';

import { ExpressFormidableOptions } from './express-formidable-options.interface.js';
Expand All @@ -21,9 +21,10 @@ export type AdminModuleOptions = {
/**
* verifies if given credentials are valid, therefore if user has access to Admin Panel
*/
authenticate: (email: string, password: string) => Promise<CurrentAdmin | null>,
authenticate?: (email: string, password: string, ctx?: any) => Promise<CurrentAdmin | null>,

Check warning on line 24 in src/interfaces/admin-module-options.interface.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
cookiePassword: string,
cookieName: string,
provider?: BaseAuthProvider,
}
/**
* Options passed to express formidable (used only by AdminJS express module)
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/abstract.loader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { AbstractHttpAdapter } from '@nestjs/core';
import AdminJS from 'adminjs';
import type AdminJS from 'adminjs';

import { AdminModuleOptions } from '../interfaces/admin-module-options.interface.js';

Expand Down
2 changes: 1 addition & 1 deletion src/loaders/express.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Injectable } from '@nestjs/common';
import { loadPackage } from '@nestjs/common/utils/load-package.util.js';
import { AbstractHttpAdapter } from '@nestjs/core';
import AdminJS from 'adminjs';
import type AdminJS from 'adminjs';

import { AdminModuleOptions } from '../interfaces/admin-module-options.interface.js';

Expand Down
2 changes: 1 addition & 1 deletion src/loaders/noop.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { Injectable } from '@nestjs/common';
import { AbstractHttpAdapter } from '@nestjs/core';
import AdminJS from 'adminjs';
import type AdminJS from 'adminjs';

import { AdminModuleOptions } from '../interfaces/admin-module-options.interface.js';

Expand Down
80 changes: 16 additions & 64 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
styled-system "^5.1.5"
text-mask-addons "^3.8.0"

"@adminjs/express@^6.0.0":
version "6.0.0"
resolved "https://registry.yarnpkg.com/@adminjs/express/-/express-6.0.0.tgz#9ad77dda79034682aee22f746f9b9460d5e5739a"
integrity sha512-TIylSszG5yUp+uHFYWWCrlztViiR05KM7suDo4SWd4UezZYc0mwNgfYPsnEmKkf5VFMEiCtYqhdCt38OxUPn/g==
"@adminjs/express@^6.1.0":
version "6.1.0"
resolved "https://registry.yarnpkg.com/@adminjs/express/-/express-6.1.0.tgz#9f5035e3d6de0b00b9ea741dde354b97c6faed6f"
integrity sha512-B3yoWGSp8xeqS/geBIKoSnMx46tbYYrbb/EmKD0SqqlVfxtBwgyoTWa6pkxqRc2T4iTMOl84VkMT0axnooAmZA==

"@ampproject/remapping@^2.2.0":
version "2.2.0"
Expand Down Expand Up @@ -2662,51 +2662,6 @@
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.3.tgz#472eaab5f15c1ffdd7f8628bd4c4f753995ec79e"
integrity sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==

"@types/babel-core@^6.25.7":
version "6.25.7"
resolved "https://registry.npmjs.org/@types/babel-core/-/babel-core-6.25.7.tgz"
integrity sha512-WPnyzNFVRo6bxpr7bcL27qXtNKNQ3iToziNBpibaXHyKGWQA0+tTLt73QQxC/5zzbM544ih6Ni5L5xrck6rGwg==
dependencies:
"@types/babel-generator" "*"
"@types/babel-template" "*"
"@types/babel-traverse" "*"
"@types/babel-types" "*"
"@types/babylon" "*"

"@types/babel-generator@*":
version "6.25.5"
resolved "https://registry.npmjs.org/@types/babel-generator/-/babel-generator-6.25.5.tgz"
integrity sha512-lhbwMlAy5rfWG+R6l8aPtJdEFX/kcv6LMFIuvUb0i89ehqgD24je9YcB+0fRspQhgJGlEsUImxpw4pQeKS/+8Q==
dependencies:
"@types/babel-types" "*"

"@types/babel-template@*":
version "6.25.2"
resolved "https://registry.npmjs.org/@types/babel-template/-/babel-template-6.25.2.tgz"
integrity sha512-QKtDQRJmAz3Y1HSxfMl0syIHebMc/NnOeH/8qeD0zjgU2juD0uyC922biMxCy5xjTNvHinigML2l8kxE8eEBmw==
dependencies:
"@types/babel-types" "*"
"@types/babylon" "*"

"@types/babel-traverse@*":
version "6.25.7"
resolved "https://registry.npmjs.org/@types/babel-traverse/-/babel-traverse-6.25.7.tgz"
integrity sha512-BeQiEGLnVzypzBdsexEpZAHUx+WucOMXW6srEWDkl4SegBlaCy+iBvRO+4vz6EZ+BNQg22G4MCdDdvZxf+jW5A==
dependencies:
"@types/babel-types" "*"

"@types/babel-types@*":
version "7.0.11"
resolved "https://registry.npmjs.org/@types/babel-types/-/babel-types-7.0.11.tgz"
integrity sha512-pkPtJUUY+Vwv6B1inAz55rQvivClHJxc9aVEPPmaq2cbyeMLCiDpbKpcKyX4LAwpNGi+SHBv0tHv6+0gXv0P2A==

"@types/babylon@*":
version "6.16.6"
resolved "https://registry.npmjs.org/@types/babylon/-/babylon-6.16.6.tgz"
integrity sha512-G4yqdVlhr6YhzLXFKy5F7HtRBU8Y23+iWy7UKthMq/OSQnL1hbsoeXESQ2LY8zEDlknipDG3nRGhUC9tkwvy/w==
dependencies:
"@types/babel-types" "*"

"@types/body-parser@*":
version "1.19.1"
resolved "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.1.tgz"
Expand Down Expand Up @@ -2849,15 +2804,6 @@
"@types/scheduler" "*"
csstype "^3.0.2"

"@types/react@^18.0.28":
version "18.0.28"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.28.tgz#accaeb8b86f4908057ad629a26635fe641480065"
integrity sha512-RD0ivG1kEztNBdoAK7lekI9M+azSnitIn85h4iOiaLjaTrMjzslhaqCGaI4IyCJ1RljWiLCEu4jyrLLgqxBTew==
dependencies:
"@types/prop-types" "*"
"@types/scheduler" "*"
csstype "^3.0.2"

"@types/[email protected]":
version "1.20.2"
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.20.2.tgz#97d26e00cd4a0423b4af620abecf3e6f442b7975"
Expand Down Expand Up @@ -3013,10 +2959,10 @@ acorn@^8.4.1, acorn@^8.5.0, acorn@^8.8.0:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.2.tgz#1b2f25db02af965399b9776b0c2c391276d37c4a"
integrity sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==

adminjs@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/adminjs/-/adminjs-7.0.0.tgz#5dad16fcdd91dfe9fd84402b3e109f9fdbb74534"
integrity sha512-6cvr04yhPpoqpK9lfy5ohxHMUI+J9lDZbRScyqzmpPTZ4P8E68unZekixx7nAGXFBmhixP5+CumLNpCNzcUeGA==
adminjs@^7.4.0:
version "7.4.0"
resolved "https://registry.yarnpkg.com/adminjs/-/adminjs-7.4.0.tgz#9551c79ac1b6047f1cc86ac1525e01660fea954a"
integrity sha512-GKot4WNEe5aQN2MLkSR216N0oE9KrpJ+COwPrYhRlF42wUMiQucwQbq36VfMb/ZsiEpF3SfBdSa9Qi6EApR0WQ==
dependencies:
"@adminjs/design-system" "^4.0.0"
"@babel/core" "^7.21.0"
Expand All @@ -3035,8 +2981,6 @@ adminjs@^7.0.0:
"@rollup/plugin-node-resolve" "^15.0.1"
"@rollup/plugin-replace" "^5.0.2"
"@rollup/plugin-terser" "^0.4.0"
"@types/babel-core" "^6.25.7"
"@types/react" "^18.0.28"
axios "^1.3.4"
commander "^10.0.0"
flat "^5.0.2"
Expand All @@ -3047,6 +2991,7 @@ adminjs@^7.0.0:
ora "^6.2.0"
prop-types "^15.8.1"
punycode "^2.3.0"
qs "^6.11.1"
react "^18.2.0"
react-dom "^18.2.0"
react-feather "^2.0.10"
Expand Down Expand Up @@ -7806,6 +7751,13 @@ qrcode-terminal@^0.12.0:
resolved "https://registry.npmjs.org/qrcode-terminal/-/qrcode-terminal-0.12.0.tgz"
integrity sha512-EXtzRZmC+YGmGlDFbXKxQiMZNwCLEO6BANKXG4iCtSIM0yqc/pappSx3RIKr4r0uh5JsBckOXeKrB3Iz7mdQpQ==

qs@^6.11.1:
version "6.11.2"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.2.tgz#64bea51f12c1f5da1bc01496f48ffcff7c69d7d9"
integrity sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==
dependencies:
side-channel "^1.0.4"

queue-microtask@^1.2.2:
version "1.2.3"
resolved "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz"
Expand Down

0 comments on commit 0793726

Please sign in to comment.