1. JWT ไปค็๏ผ
ๅ็ซฏๅ้็ๅฝขๅผๆ๏ผ
- Bearer TOKEN_STRING
- TOKEN_STRING
- JWT TOKEN_STRING
ๆณจๆ๏ผTOKEN_STRING ๆฏๆฒกๆๅผๅท็
ๅ็ซฏๅ้id็ญๆฐๅญๆถ้่ฝฌไธบstring๏ผ
@bp.route('/login', methods=['POST'])
def login():
data = request.get_json() or {}
if not data.get('username') or not data.get('password'):
return jsonify({"msg": "Username and password required"}), 400
user = User.query.filter_by(username=data.get('username'), is_deleted=False).first()
if user is None or not user.check_password(data.get('password')):
return jsonify({"msg": "Invalid username or password"}), 401
# Create both access and refresh tokens
# ๆณจๆ๏ผ่ฟ้ๆฐๅญ่ฎฐๅพ่ฝฌๆขๆstring
access_token = create_access_token(identity=str(user.id))
refresh_token = create_refresh_token(identity=str(user.id))
# Return both tokens and user information
return jsonify({
"access_token": access_token,
"refresh_token": refresh_token,
"user": user.to_dict(include_contact=True)
}), 200