Skip to content

Commit a19e196

Browse files
committed
redirect after login back to page
1 parent f3e02fc commit a19e196

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

src/components/ChatWidget.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,31 @@ placeholder for Opey II Chat widget
33
-->
44
<script lang="ts">
55
6-
import { ref, reactive } from 'vue'
6+
import { ref, reactive, computed } from 'vue'
77
import { Close, Top as ElTop, WarnTriangleFilled } from '@element-plus/icons-vue'
88
import { ElMessage } from 'element-plus'
99
import ChatMessage from './ChatMessage.vue';
1010
import { v4 as uuidv4 } from 'uuid';
1111
import { OpeyMessage, UserMessage } from '@/models/MessageModel';
1212
import { getCurrentUser } from '@/obp';
1313
import { useChat } from '@/stores/chat';
14+
import { useRoute } from 'vue-router'
1415
1516
export default {
1617
setup () {
18+
const route = useRoute()
19+
const getLoginUrl = computed(() => {
20+
const currentPath = route.path
21+
const queryString = new URLSearchParams(route.query as Record<string, string>).toString()
22+
const fullPath = queryString ? `${currentPath}?${queryString}` : currentPath
23+
return `/api/oauth2/connect?redirect=${encodeURIComponent(fullPath)}`
24+
})
25+
1726
return {
1827
Close,
1928
ElTop,
2029
WarnTriangleFilled,
30+
getLoginUrl,
2131
}
2232
},
2333
data() {
@@ -125,7 +135,7 @@ export default {
125135
</div>
126136
<div v-else-if="!chat.userIsAuthenticated" class="login-container">
127137
<p class="login-message" size="large">Opey is only available once logged on.</p>
128-
<a href="/api/oauth2/connect" class="login-button router-link">Log on</a>
138+
<a :href="getLoginUrl" class="login-button router-link">Log on</a>
129139
</div>
130140
<div v-else class="messages-container" v-bind:class="{ disabled: !chat.userIsAuthenticated }">
131141
<el-scrollbar>

src/components/ChatWidgetOld.vue

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import axios from 'axios';
3232
import 'prismjs/themes/prism.css'; // Choose a theme you like
3333
import { v4 as uuidv4 } from 'uuid';
34-
import { inject } from 'vue';
34+
import { inject, computed } from 'vue';
3535
import { obpApiHostKey } from '@/obp/keys';
3636
import { getCurrentUser } from '../obp';
3737
import { getOpeyJWT, getobpConsent, answerobpConsentChallenge } from '@/obp/common-functions'
@@ -40,6 +40,7 @@
4040
import { useConnectionStore } from '@/stores/connection';
4141
import { useChatStore } from '@/stores/chat';
4242
import { ElMessage } from 'element-plus';
43+
import { useRoute } from 'vue-router';
4344
4445
import 'prismjs/components/prism-markup';
4546
import 'prismjs/components/prism-javascript';
@@ -73,7 +74,15 @@
7374
7475
const { isConnected } = storeToRefs(connectionStore);
7576
76-
return {isStreaming, chatMessages, lastError, currentMessageSnapshot, chatStore, connectionStore}
77+
const route = useRoute();
78+
const loginUrl = computed(() => {
79+
const currentPath = route.path;
80+
const queryString = new URLSearchParams(route.query as Record<string, string>).toString();
81+
const fullPath = queryString ? `${currentPath}?${queryString}` : currentPath;
82+
return `/api/oauth2/connect?redirect=${encodeURIComponent(fullPath)}`;
83+
});
84+
85+
return {isStreaming, chatMessages, lastError, currentMessageSnapshot, chatStore, connectionStore, loginUrl}
7786
},
7887
data() {
7988
return {
@@ -378,7 +387,7 @@
378387

379388
</div>
380389
<div v-else class="chat-messages">
381-
<p>Opey is only availabled when logged in. <a v-bind:href="'/api/oauth2/connect'">Log In</a> </p>
390+
<p>Opey is only availabled when logged in. <a v-bind:href="loginUrl">Log In</a> </p>
382391
</div>
383392
<el-alert
384393
v-if="this.errorState"

src/components/HeaderNav.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ watchEffect(() => {
193193
194194
const getCurrentPath = () => {
195195
const currentPath = route.path
196-
return currentPath
196+
const queryString = new URLSearchParams(route.query as Record<string, string>).toString()
197+
return queryString ? `${currentPath}?${queryString}` : currentPath
197198
}
198199
199200
</script>

0 commit comments

Comments
 (0)