domain bug fix
This commit is contained in:
@@ -11,11 +11,17 @@ export interface IUserState{
|
||||
|
||||
export const useAuthStore = defineStore({
|
||||
id: 'auth',
|
||||
state: () :IUserState => ({
|
||||
token: localStorage.getItem('token')||'',
|
||||
returnUrl: '',
|
||||
currentDomain: JSON.parse(localStorage.getItem('currentDomain')||"{}")
|
||||
}),
|
||||
state: ():IUserState =>{
|
||||
const token=localStorage.getItem('token')||'';
|
||||
if(token!==''){
|
||||
api.defaults.headers["Authorization"]='Bearer ' + token;
|
||||
}
|
||||
return {
|
||||
token,
|
||||
returnUrl: '',
|
||||
currentDomain: JSON.parse(localStorage.getItem('currentDomain')||"{}")
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async login(username:string, password:string) {
|
||||
const params = new URLSearchParams();
|
||||
@@ -26,6 +32,7 @@ export const useAuthStore = defineStore({
|
||||
console.info(result);
|
||||
this.token =result.data.access_token;
|
||||
localStorage.setItem('token', result.data.access_token);
|
||||
api.defaults.headers["Authorization"]='Bearer ' + this.token;
|
||||
this.currentDomain=await this.getCurrentDomain();
|
||||
localStorage.setItem('currentDomain',JSON.stringify(this.currentDomain));
|
||||
Router.push(this.returnUrl || '/');
|
||||
@@ -37,22 +44,23 @@ export const useAuthStore = defineStore({
|
||||
}
|
||||
},
|
||||
async getCurrentDomain():Promise<IDomainInfo>{
|
||||
const activedomain = await api.get(`http://127.0.0.1:8000/api/activedomain`);
|
||||
return {
|
||||
domainName:'mfu07rkgnb7c',
|
||||
kintoneUrl:'https://mfu07rkgnb7c.cybozu.com'
|
||||
id:activedomain.data.id,
|
||||
domainName:activedomain.data.name,
|
||||
kintoneUrl:activedomain.data.url
|
||||
}
|
||||
},
|
||||
async getUserDomains():Promise<IDomainInfo[]>{
|
||||
return [
|
||||
{
|
||||
domainName:'mfu07rkgnb7c',
|
||||
kintoneUrl:'https://mfu07rkgnb7c.cybozu.com'
|
||||
},
|
||||
{
|
||||
domainName:'alicorn',
|
||||
kintoneUrl:'https://alicorn.cybozu.com'
|
||||
const resp = await api.get(`http://127.0.0.1:8000/api/domain`);
|
||||
const domains =resp.data as any[];
|
||||
return domains.map(data=>{
|
||||
return {
|
||||
id:data.id,
|
||||
domainName:data.name,
|
||||
kintoneUrl:data.url
|
||||
}
|
||||
]
|
||||
});
|
||||
},
|
||||
logout() {
|
||||
this.token = undefined;
|
||||
@@ -60,7 +68,11 @@ export const useAuthStore = defineStore({
|
||||
localStorage.removeItem('currentDomain');
|
||||
Router.push('/login');
|
||||
},
|
||||
setCurrentDomain(domain:IDomainInfo){
|
||||
async setCurrentDomain(domain:IDomainInfo){
|
||||
if(domain.id===this.currentDomain.id){
|
||||
return;
|
||||
}
|
||||
await api.put(`http://127.0.0.1:8000/api/activedomain/${domain.id}`);
|
||||
this.currentDomain=domain;
|
||||
localStorage.setItem('currentDomain',JSON.stringify(this.currentDomain));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user