From d3e7ab1aa13ab040b54b5d2b1621ada63c1aed5f Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Fri, 17 Nov 2023 13:15:16 -0300 Subject: [PATCH] Fix bugs of original data Return user_id on /auth/login and create database if it wasn't created --- data/sample-api-users/src/__init__.py | 4 +++- data/sample-api-users/src/api/auth.py | 2 +- data/sample-api-users/src/api/models/users.py | 5 ++++- data/sample-client-users/src/Api.ts | 1 - 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/data/sample-api-users/src/__init__.py b/data/sample-api-users/src/__init__.py index 32deb4b..b8714f6 100644 --- a/data/sample-api-users/src/__init__.py +++ b/data/sample-api-users/src/__init__.py @@ -33,4 +33,6 @@ def create_app(script_info=None): def ctx(): return {"app": app, "db": db} - return app + with app.app_context(): + db.create_all() + return app diff --git a/data/sample-api-users/src/api/auth.py b/data/sample-api-users/src/api/auth.py index fa14c74..6bce4b1 100644 --- a/data/sample-api-users/src/api/auth.py +++ b/data/sample-api-users/src/api/auth.py @@ -54,7 +54,7 @@ class Login(Resource): access_token = user.encode_token(user.id, "access") refresh_token = user.encode_token(user.id, "refresh") - response_object = {"access_token": access_token, "refresh_token": refresh_token} + response_object = {"access_token": access_token, "refresh_token": refresh_token, "user_id": user.id} return response_object, 200 diff --git a/data/sample-api-users/src/api/models/users.py b/data/sample-api-users/src/api/models/users.py index 3a67e3a..3c8ff47 100644 --- a/data/sample-api-users/src/api/models/users.py +++ b/data/sample-api-users/src/api/models/users.py @@ -111,5 +111,8 @@ class User(db.Model): return namespace.clone( "Access and Refresh Token", cls.get_api_auth_refresh_model(namespace), - {"access_token": fields.String(required=True)}, + { + "access_token": fields.String(required=True), + "user_id": fields.Integer(readOnly=True), + }, ) diff --git a/data/sample-client-users/src/Api.ts b/data/sample-client-users/src/Api.ts index 7938628..348d79e 100644 --- a/data/sample-client-users/src/Api.ts +++ b/data/sample-client-users/src/Api.ts @@ -2,7 +2,6 @@ import { Axios, AxiosError } from "axios"; import { Credentials, Token, User, Zone } from "./Types"; const instance = new Axios({ - // baseURL: "http://api:5000/", baseURL: "/api/", headers: { accept: "application/json",