Skip to content

Add multiple user roles #805

Answered by jasonreiche
imjulianeral asked this question in Help
Oct 28, 2020 · 9 comments · 29 replies
Discussion options

You must be logged in to vote

I have roles working.

models/index.js

import User, { UserSchema } from "./User"

export default {
  User: {
    model: User,
    schema: UserSchema
  }
}

models/User.js

import Adapters from "next-auth/adapters"

// Extend the built-in models using class inheritance
export default class User extends Adapters.TypeORM.Models.User.model {
  constructor(name, email, image, emailVerified, roles) {
    super(name, email, image, emailVerified)
    if (roles) { this.roles = roles}
  }
}

export const UserSchema = {
  name: "User",
  target: User,
  columns: {
    ...Adapters.TypeORM.Models.User.schema.columns,
    roles: {
      type: "varchar",
      nullable: true
    },
  },
}

pages/api/auth/[.…

Replies: 9 comments 29 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
20 replies
@IzaanAnwar
Comment options

@GlennStreetman
Comment options

@nedelyux
Comment options

@rockingrohit9639
Comment options

@xcaeser
Comment options

Answer selected by balazsorban44
Comment options

You must be logged in to vote
2 replies
@michaelcmelton
Comment options

@jasonreiche
Comment options

Comment options

You must be logged in to vote
2 replies
@myhendry
Comment options

@nhnasem
Comment options

Comment options

You must be logged in to vote
3 replies
@Pelps12
Comment options

@myhendry
Comment options

@Pelps12
Comment options

Comment options

You must be logged in to vote
2 replies
@arturs706
Comment options

@DiegoGonzalezCruz
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
Converted from issue

This discussion was converted from issue #805 on December 07, 2020 16:49.