dashboard/api/auth.py
2021-09-27 12:03:35 +02:00

21 lines
608 B
Python

from flask import request, jsonify
from flask_jwt_extended import create_access_token
from flask_cors import cross_origin
from . import api_v1
USERNAME = 'admin'
PASSWORD = 'admin'
@api_v1.route('/login', methods=['POST'])
@cross_origin()
def login():
username = request.json.get('username')
password = request.json.get('password')
if username != USERNAME or password != PASSWORD:
return jsonify({'errorMessage': 'Invalid username or password'}), 401
access_token = create_access_token(identity=username)
return jsonify({'username': USERNAME, 'access_token': access_token})