Skip to content

Commit e47d02f

Browse files
author
Vianpyro
committed
Added JWT
1 parent 46f7a4f commit e47d02f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

app.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
from datetime import timedelta
22
from flask import Flask
3+
from flask_jwt_extended import JWTManager
34
from config import Config
45
from routes import register_routes
56
from error_handlers import register_error_handlers
7+
from dotenv import load_dotenv
8+
import os
9+
10+
# Load environment variables from .env file
11+
load_dotenv()
612

713
app = Flask(__name__)
14+
15+
# Load configuration from Config class
816
app.config.from_object(Config)
917

18+
# Set JWT configuration from environment variables
19+
app.config['JWT_SECRET_KEY'] = os.getenv('JWT_SECRET_KEY')
1020
app.config['JWT_ACCESS_TOKEN_EXPIRES'] = timedelta(minutes=15)
1121
app.config['JWT_REFRESH_TOKEN_EXPIRES'] = timedelta(days=30)
1222

23+
# Initialize JWTManager with the Flask app
24+
jwt = JWTManager(app)
25+
1326
@app.route('/')
1427
def home():
1528
return "Hello there!"
@@ -19,4 +32,5 @@ def home():
1932
register_error_handlers(app)
2033

2134
if __name__ == '__main__':
22-
app.run(host='0.0.0.0', port=29565, debug=False)
35+
# Run the app with specified host and port from environment variables
36+
app.run(host='0.0.0.0', port=int(os.getenv('PORT', 5000)), debug=False)

jwt_key_generator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import secrets
2+
3+
secret_key = secrets.token_urlsafe(64)
4+
print(secret_key)

0 commit comments

Comments
 (0)