Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hi Guys,

I'm new to AdminJS and I couldn't find the answer anywhere else. That is why raising this query here.

I created new adminjs project and added Sequelize as ORM. (I use MySQL).

Now, I would like the adminjs to pickup my table "Auth" as Resource. I tried adding the resource inside options.ts and tested, it is not showing in navigation panel.

Tried adding the whole database also inside options.ts and still not showing up. Am I missing something here? This is just fresh app with nothing else added except only one entity file. Can someone please guide me what am I missing here?

auth.entity.ts

import { DataTypes, Model, Optional } from 'sequelize'
import sequelize from '../config.js';

interface IAuth {
  id: number;
  email: string;
  createdAt: Date;
  password: string;
  isValid: string;
}

export type CategoryCreationAttributes = Optional<IAuth, 'id'>

export class Auth extends Model<IAuth, CategoryCreationAttributes> {
  declare id: number;
  declare email: string;
  declare createdAt: Date;
  declare password: string;
  declare isValid: string;
}

Auth.init(
    {
      id: {
        type: DataTypes.INTEGER,
        autoIncrement: true,
        primaryKey: true,
      },
      email: {
        type: new DataTypes.STRING(128),
        allowNull: false,
      },
      password: {
        type: new DataTypes.STRING(128),
        allowNull: false,
      },
      isValid: {
        type: new DataTypes.STRING(128),
        allowNull: false,
      },
      createdAt: {
        type: DataTypes.DATE,
      }
    },
    {
      sequelize,
      tableName: 'auth',
      modelName: 'Auth',
    }
  )

options.ts file

import { AdminJSOptions } from 'adminjs';

import componentLoader from './component-loader.js';

import { Auth } from '../db/models/auth.entity.js';

import dbTest from '../db/config.js';

const options: AdminJSOptions = {
  componentLoader,
  rootPath: '/admin',
  resources: [
    Auth
  ],
  databases: [],
};

export default options;

app.ts

import express from 'express';
import AdminJS from 'adminjs';
import { buildAuthenticatedRouter } from '@adminjs/express';

import provider from './admin/auth-provider.js';
import options from './admin/options.js';
import initializeDb from './db/index.js';

const port = process.env.PORT || 3000;

const start = async () => {
  const app = express();

  await initializeDb();

  const admin = new AdminJS(options);

  if (process.env.NODE_ENV === 'production') {
    await admin.initialize();
  } else {
    admin.watch();
  }

  const router = buildAuthenticatedRouter(
    admin,
    {
      cookiePassword: process.env.COOKIE_SECRET,
      cookieName: 'adminjs',
      provider,
    },
    null,
    {
      secret: process.env.COOKIE_SECRET,
      saveUninitialized: true,
      resave: true,
    },
  );

  app.use(admin.options.rootPath, router);

  app.listen(port, () => {
    console.log(`AdminJS available at http://localhost:${port}${admin.options.rootPath}`);
  });
};

start();
You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.