Skip to content

Commit 1f294e9

Browse files
committed
Add Models to JWTRoutes class & init_app method #119
1 parent 848a88e commit 1f294e9

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ class UserModel(db.Model):
8181
# You can define the primary key name with `ENTITY_KEY` on Flask's config
8282
app.config["ENTITY_KEY"] = "user_id"
8383
# (`id` is used by default)
84-
JwtRoutes(app)
85-
86-
# You can also specify a list of entity model classes
84+
JwtRoutes(app, entity_models=[UserModel, TeacherModel, ...etc])
8785

88-
app.config["ENTITY_MODELS"] = [ UserModel, TeacherModel, ...etc ]
86+
# Or pass later with `init_app`
87+
def create_app(config):
88+
...
89+
jwt_routes.init_app(app, entity_models=[UserModel, TeacherModel, ...etc])
8990

9091
```
9192

@@ -181,7 +182,9 @@ An Example configuration for registering & logging in users of different types:
181182
("POST", "/auth/user"), ("POST", "/auth/user/login"),
182183
("POST", "/auth/teacher"), ("POST", "/auth/teacher/login"),
183184
]
184-
app.config["ENTITY_MODELS"] = [UserModel, TeacherModel]
185+
186+
# Optionally, you can pass your models to Flask's config:
187+
app.config["ENTITY_MODELS"] = [ UserModel, TeacherModel, ...etc ]
185188
```
186189
## Authors
187190

flask_jwt_router/_jwt_routes.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,16 @@ def register():
6666
# Create your entity model (example uses Flask-SqlAlchemy)
6767
6868
class UserModel(db.Model):
69+
__tablename__ = "users"
6970
id = db.Column(db.Integer, primary_key=True)
7071
name = db.Column(db.String)
7172
72-
# You can also specify a list of entity model classes
73+
JwtRoutes(app, entity_models=[UserModel, TeacherModel, ...etc])
7374
74-
app.config["ENTITY_MODELS"] = [ UserModel, TeacherModel ]
75-
76-
# (`id` is used by default)
77-
JwtRoutes(app)
75+
# Or pass later with `init_app`
76+
def create_app(config):
77+
...
78+
jwt_routes.init_app(app, entity_models=[UserModel, TeacherModel, ...etc])
7879
7980
8081
Authorization & Tokens

0 commit comments

Comments
 (0)