Better AuthBA
Better Auth7mo ago
Al

Extending user schema

I'm not necessarily sure whether my design decision was right here but I am making an internal tool and I want to set it up so that each user has a list of allowed tabs they can view. I'm using the drizzle adapter and I felt the most natural type for the allowedTabs column would be an enum array. From what I understand, I don't think changes to schemas are automatically inferred in the functions/endpoints that work with the user or session objects and if you want this type inference you need to use the additionalFields property in the user/session objects of the auth config. However, I don't think the enum array type that I chose for this tabs column is supported.

I have a couple of questions
  1. This is mainly because I'm curious, but how big of a task would it be to figure out automatic type inference directly from schemas instead of the additional fields property? I feel like this would be a much better DX, but I'm also not experienced enough to understand the difficulties in setting up something like this and I'm thinking it's probably extremely dependent on choice of DB + adapter.
  2. It kind of seems like the organizations plug in could fit this user access I want to implement but I'm not sure whether it's overkill for my use case. Would greatly appreciate some insight into whether the organizations plugin seems like a right fit here.
I mainly want to access this allowedTabs list from the session object and I think I can also use the customSession plugin which seems like a better option than the organizations plugin but it would be nice if the type was inferred automatically from my drizzle schema and I think it would save me an extra db trip.

Thanks in advance!
Was this page helpful?