55from pydantic import ValidationError
66
77from fastapi_forge .dtos import (
8+ CustomEnum ,
9+ CustomEnumValue ,
810 Model ,
911 ModelField ,
1012 ModelFieldMetadata ,
1113 ModelMetadata ,
1214)
1315from fastapi_forge .enums import FieldDataTypeEnum
1416from fastapi_forge .forge import build_project
15- from fastapi_forge .frontend .constants import DEFAULT_AUTH_USER_FIELDS
17+ from fastapi_forge .frontend .constants import (
18+ DEFAULT_AUTH_USER_FIELDS ,
19+ DEFAULT_AUTH_USER_ROLE_ENUM_NAME ,
20+ )
1621from fastapi_forge .frontend .notifications import notify_validation_error
1722from fastapi_forge .frontend .state import state
1823
@@ -210,6 +215,23 @@ async def _handle_builtin_auth_change(
210215 return
211216
212217 try :
218+ auth_role_enum_name = DEFAULT_AUTH_USER_ROLE_ENUM_NAME
219+ auth_enum = state .get_enum_by_name (auth_role_enum_name )
220+
221+ auth_enum_values = [
222+ CustomEnumValue (name = "USER" , value = "auto()" ),
223+ CustomEnumValue (name = "ADMIN" , value = "auto()" ),
224+ ]
225+ if auth_enum and not auth_enum .values :
226+ auth_enum .values = auth_enum_values
227+
228+ if not auth_enum :
229+ auth_enum = CustomEnum (
230+ name = auth_role_enum_name ,
231+ values = auth_enum_values ,
232+ )
233+ state .custom_enums .append (auth_enum )
234+
213235 auth_user_model = Model (
214236 name = "auth_user" ,
215237 metadata = ModelMetadata (is_auth_model = True ),
@@ -222,6 +244,12 @@ async def _handle_builtin_auth_change(
222244 index = True ,
223245 ),
224246 * DEFAULT_AUTH_USER_FIELDS ,
247+ ModelField (
248+ name = "role" ,
249+ type = FieldDataTypeEnum .ENUM ,
250+ type_enum = auth_role_enum_name ,
251+ default_value = auth_enum .values [0 ].name ,
252+ ),
225253 ModelField (
226254 name = "created_at" ,
227255 type = FieldDataTypeEnum .DATETIME ,
0 commit comments