API token

This commit is contained in:
2023-11-04 17:16:57 +09:00
parent 26890f5b35
commit 761eb4c13e
2 changed files with 17 additions and 10 deletions

View File

@@ -3,8 +3,8 @@ import base64
PROJECT_NAME = "KintoneAppBuilder"
# SQLALCHEMY_DATABASE_URI = "postgres://maxz64:m@xz1205@alicornkintone.postgres.database.azure.com/postgres"
SQLALCHEMY_DATABASE_URI = "postgres://kabAdmin:P@ssw0rd!@kintonetooldb.postgres.database.azure.com/postgres"
SQLALCHEMY_DATABASE_URI = "postgres://maxz64:m@xz1205@alicornkintone.postgres.database.azure.com/postgres"
#SQLALCHEMY_DATABASE_URI = "postgres://kabAdmin:P@ssw0rd!@kintonetooldb.postgres.database.azure.com/postgres"
API_V1_STR = "/k/v1"

View File

@@ -5,12 +5,18 @@ import { Router } from '../router';
export const useAuthStore = defineStore({
id: 'auth',
state: () => ({
token: localStorage.getItem('token'),
name:localStorage.getItem('name'),
domain:localStorage.getItem('domain'),
returnUrl: ''
}),
state: () =>{
const token=localStorage.getItem('token');
if(token && token!==''){
api.defaults.headers["Authorization"]='Bearer ' + token;
}
return {
token: token,
name:localStorage.getItem('name'),
domain:localStorage.getItem('domain'),
returnUrl: ''
}
},
actions: {
async login(username:string, password:string) {
const params = new URLSearchParams();
@@ -24,8 +30,9 @@ export const useAuthStore = defineStore({
localStorage.setItem('token', result.data.access_token);
localStorage.setItem('id', result.data.user_id);
localStorage.setItem('name', result.data.user_name);
const config = {headers:{Authorization : 'Bearer ' + this.token}};
const activedomain = await api.get(`http://127.0.0.1:8000/api/activedomain`,config);
// const config = {headers:{Authorization : 'Bearer ' + this.token}};
api.defaults.headers["Authorization"]='Bearer ' + this.token;
const activedomain = await api.get(`http://127.0.0.1:8000/api/activedomain`);
this.domain = activedomain.data.name;
localStorage.setItem('domain', activedomain.data.name);
Router.push(this.returnUrl || '/');