Skip to content

Uncaught exception in middleware #3496

Answered by tomgobich
DZ8540 asked this question in Help
Discussion options

You must be logged in to vote

If I had to guess I'd say it's because your this.checkAdminRole call in your middleware is missing await, since the method is async.

As for your second question, in order to get the role properties you'll either need to load it or query it separately. Typically, what I do is have a seed that explicitly sets the role's ids. Then, define an enum within my application called Roles with each role record. This way I can perform the check without needing to make an additional database call.

For example:

// contracts/Enums/Roles.ts

enum Roles {
  ADMIN = 1,
  USER = 2
}

export default Roles
// app/Services/RoleService.ts

import Roles from 'Contracts/Enums/Roles'

export default class RoleService

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
7 replies
@DZ8540
Comment options

@tomgobich
Comment options

@DZ8540
Comment options

@tomgobich
Comment options

@DZ8540
Comment options

Answer selected by DZ8540
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants