Optimize the auth flow (#68)
Co-authored-by: AceDataCloud <office@acedata.cloud>
This commit is contained in:
1 parent
033cbc082c
commit
85aef535f6
23 files changed
+215
-245
No files matched your search
@@ -1,46 +1,20 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { IUser, IToken } from '@/models';
|
||||
|
||||
interface IData {
|
||||
accessToken: string | undefined;
|
||||
refreshToken: string | undefined;
|
||||
redirect: string | undefined;
|
||||
code: string | undefined;
|
||||
user: IUser | undefined;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'AuthCallback',
|
||||
data(): IData {
|
||||
return {
|
||||
accessToken: undefined,
|
||||
refreshToken: undefined,
|
||||
redirect: this.$route.query.redirect?.toString(),
|
||||
code: this.$route.query.code?.toString(),
|
||||
user: undefined
|
||||
redirect: this.$route.query.redirect?.toString()
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
// if auth code is provided, get token via oauth
|
||||
if (this.code) {
|
||||
const data: IToken = await this.$store.dispatch('getToken', this.code);
|
||||
this.accessToken = data.access;
|
||||
this.refreshToken = data.refresh;
|
||||
} else {
|
||||
this.$store.dispatch('resetToken');
|
||||
return;
|
||||
}
|
||||
// if token acquired, get user info
|
||||
if (this.accessToken && this.refreshToken) {
|
||||
const user = await this.$store.dispatch('getUser');
|
||||
this.user = user;
|
||||
if (this.redirect) {
|
||||
await this.$router.push(this.redirect);
|
||||
}
|
||||
} else {
|
||||
// reset token and trigger popup login window
|
||||
this.$store.dispatch('resetToken');
|
||||
if (this.redirect) {
|
||||
await this.$router.push(this.redirect);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { getBaseUrlAuth, getBaseUrlHub } from '@/utils';
|
||||
import { login } from '@/utils';
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
interface IData {
|
||||
@@ -14,13 +14,7 @@ export default defineComponent({
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
const hubBaseUrl = getBaseUrlHub();
|
||||
const authBaseUrl = getBaseUrlAuth();
|
||||
// callback url used to init access token and then redirect back of `redirect`
|
||||
const callbackUrl = `${hubBaseUrl}/auth/callback?redirect=${this.redirect}`;
|
||||
// redirect to auth service to get access token then redirect back
|
||||
const targetUrl = `${authBaseUrl}/auth/login?redirect=${callbackUrl}`;
|
||||
window.location.href = targetUrl;
|
||||
login(this.redirect);
|
||||
},
|
||||
methods: {}
|
||||
});
|
||||
|
||||
@@ -128,10 +128,28 @@ export default defineComponent({
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.onScrollDown();
|
||||
async mounted() {
|
||||
await this.onGetService();
|
||||
await this.onGetApplication();
|
||||
await this.onGetConversations();
|
||||
await this.onScrollDown();
|
||||
},
|
||||
methods: {
|
||||
async onGetService() {
|
||||
console.debug('start onGetService');
|
||||
await this.$store.dispatch('chat/getService');
|
||||
console.debug('end onGetService');
|
||||
},
|
||||
async onGetApplication() {
|
||||
console.debug('start onGetApplication');
|
||||
await this.$store.dispatch('chat/getApplication');
|
||||
console.debug('end onGetApplication');
|
||||
},
|
||||
async onGetConversations() {
|
||||
console.debug('start onGetConversations');
|
||||
await this.$store.dispatch('chat/getConversations');
|
||||
console.debug('end onGetConversations');
|
||||
},
|
||||
async onDraft(question: string) {
|
||||
this.question = question;
|
||||
this.onSubmit();
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
:need-apply="needApply"
|
||||
@refresh="onGetApplication"
|
||||
/>
|
||||
<task-list @custom="onCustom" @refresh="onGetApplication" />
|
||||
<task-list @custom="onCustom" />
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<el-card v-show="operating" class="operations">
|
||||
@@ -66,6 +66,7 @@ interface IData {
|
||||
ignore: string;
|
||||
references: string[];
|
||||
operating: boolean;
|
||||
job: number;
|
||||
}
|
||||
|
||||
const CALLBACK_URL = 'https://webhook.acedata.cloud/midjourney';
|
||||
@@ -90,7 +91,8 @@ export default defineComponent({
|
||||
elements: [],
|
||||
ignore: '',
|
||||
references: [],
|
||||
operating: false
|
||||
operating: false,
|
||||
job: 0
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -106,6 +108,9 @@ export default defineComponent({
|
||||
preset() {
|
||||
return this.$store.state.midjourney.preset;
|
||||
},
|
||||
loading() {
|
||||
return this.$store.state.midjourney.status.getApplication === Status.Request;
|
||||
},
|
||||
initializing() {
|
||||
return this.$store.state.midjourney.status.getApplication === Status.Request;
|
||||
},
|
||||
@@ -198,7 +203,31 @@ export default defineComponent({
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
await this.onGetService();
|
||||
await this.onGetApplication();
|
||||
await this.onScrollDown();
|
||||
await this.onGetTasks();
|
||||
await this.onScrollDown();
|
||||
// @ts-ignore
|
||||
this.job = setInterval(() => {
|
||||
this.onGetTasks();
|
||||
}, 5000);
|
||||
},
|
||||
async unmounted() {
|
||||
clearInterval(this.job);
|
||||
},
|
||||
methods: {
|
||||
async onGetService() {
|
||||
console.debug('start onGetService');
|
||||
await this.$store.dispatch('midjourney/getService');
|
||||
console.debug('end onGetService');
|
||||
},
|
||||
async onGetApplication() {
|
||||
console.debug('start onGetApplication');
|
||||
await this.$store.dispatch('midjourney/getApplication');
|
||||
console.debug('end onGetApplication');
|
||||
},
|
||||
onApply() {
|
||||
applicationOperator
|
||||
.create({
|
||||
@@ -215,9 +244,6 @@ export default defineComponent({
|
||||
}
|
||||
});
|
||||
},
|
||||
async onGetApplication() {
|
||||
await this.$store.dispatch('midjourney/getApplication');
|
||||
},
|
||||
async onStartTask(request: IMidjourneyImagineRequest) {
|
||||
const token = this.credential?.token;
|
||||
if (!token) {
|
||||
@@ -236,7 +262,7 @@ export default defineComponent({
|
||||
ElMessage.error(this.$t('midjourney.message.startTaskFailed'));
|
||||
})
|
||||
.finally(async () => {
|
||||
await this.onSyncTasks();
|
||||
await this.onGetTasks();
|
||||
await this.onScrollDown();
|
||||
});
|
||||
},
|
||||
@@ -271,7 +297,11 @@ export default defineComponent({
|
||||
}
|
||||
}, 500);
|
||||
},
|
||||
async onSyncTasks() {
|
||||
async onGetTasks() {
|
||||
if (this.loading) {
|
||||
console.debug('loading');
|
||||
return;
|
||||
}
|
||||
await this.$store.dispatch('midjourney/getTasks', {
|
||||
limit: 30,
|
||||
offset: 0
|
||||
|
||||
@@ -35,6 +35,7 @@ const CALLBACK_URL = 'https://webhook.acedata.cloud/qrart';
|
||||
|
||||
interface IData {
|
||||
task: IQrartTask | undefined;
|
||||
job: number;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
@@ -48,10 +49,14 @@ export default defineComponent({
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
task: undefined
|
||||
task: undefined,
|
||||
job: 0
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
loading() {
|
||||
return this.$store.state.qrart?.status?.getApplication === Status.Request;
|
||||
},
|
||||
service() {
|
||||
return this.$store.state.qrart.service;
|
||||
},
|
||||
@@ -71,7 +76,31 @@ export default defineComponent({
|
||||
return this.$store.state.qrart.application;
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
await this.onGetService();
|
||||
await this.onGetApplication();
|
||||
await this.onScrollDown();
|
||||
await this.onGetTasks();
|
||||
await this.onScrollDown();
|
||||
// @ts-ignore
|
||||
this.job = setInterval(() => {
|
||||
this.onGetTasks();
|
||||
}, 5000);
|
||||
},
|
||||
async unmounted() {
|
||||
clearInterval(this.job);
|
||||
},
|
||||
methods: {
|
||||
async onGetService() {
|
||||
console.debug('start onGetService');
|
||||
await this.$store.dispatch('qrart/getService');
|
||||
console.debug('end onGetService');
|
||||
},
|
||||
async onGetApplication() {
|
||||
console.debug('start onGetApplication');
|
||||
await this.$store.dispatch('qrart/getApplication');
|
||||
console.debug('end onGetApplication');
|
||||
},
|
||||
onApply() {
|
||||
applicationOperator
|
||||
.create({
|
||||
@@ -88,9 +117,6 @@ export default defineComponent({
|
||||
}
|
||||
});
|
||||
},
|
||||
async onGetApplication() {
|
||||
await this.$store.dispatch('qrart/getApplication');
|
||||
},
|
||||
async onScrollDown() {
|
||||
setTimeout(() => {
|
||||
// scroll to bottom for `.tasks`
|
||||
@@ -100,6 +126,16 @@ export default defineComponent({
|
||||
}
|
||||
}, 500);
|
||||
},
|
||||
async onGetTasks() {
|
||||
if (this.loading) {
|
||||
console.debug('loading');
|
||||
return;
|
||||
}
|
||||
await this.$store.dispatch('qrart/getTasks', {
|
||||
limit: 30,
|
||||
offset: 0
|
||||
});
|
||||
},
|
||||
async onGenerate() {
|
||||
const request = {
|
||||
type: this.config?.type,
|
||||
@@ -142,10 +178,7 @@ export default defineComponent({
|
||||
ElMessage.error(this.$t('qrart.message.startTaskFailed'));
|
||||
})
|
||||
.finally(async () => {
|
||||
await this.$store.dispatch('qrart/getTasks', {
|
||||
limit: 50,
|
||||
offset: 0
|
||||
});
|
||||
await this.onGetTasks();
|
||||
await this.onScrollDown();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user