File tree 2 files changed +59
-0
lines changed
2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div class =" flex items-center justify-center min-h-screen" >
3
+ <Spinner />
4
+ </div >
5
+ </template >
6
+
7
+ <script setup>
8
+ import { onMounted } from ' vue' ;
9
+ import { useUserStore } from ' @/stores/user' ;
10
+ import { useRouter } from ' vue-router' ;
11
+ import { callAdminForthApi } from ' @/utils' ;
12
+ import { Spinner } from ' @/afcl' ;
13
+
14
+ const router = useRouter ();
15
+ const userStore = useUserStore ();
16
+
17
+ onMounted (async () => {
18
+ const urlParams = new URLSearchParams (window .location .search );
19
+ const code = urlParams .get (' code' );
20
+ const state = urlParams .get (' state' );
21
+
22
+ if (code && state) {
23
+ const encodedCode = encodeURIComponent (code);
24
+ const encodedState = encodeURIComponent (state);
25
+ const response = await callAdminForthApi ({
26
+ path: ` /oauth/callback?code=${ encodedCode} &state=${ encodedState} ` ,
27
+ method: ' GET' ,
28
+ });
29
+ if (response .allowedLogin ) {
30
+ await userStore .finishLogin ();
31
+ } else if (response .redirectTo ) {
32
+ router .push (response .redirectTo );
33
+ } else if (response .error ) {
34
+ router .push ({
35
+ name: ' login' ,
36
+ query: { error: response .error }
37
+ });
38
+ }
39
+ } else {
40
+ router .push ({ name: ' login' });
41
+ }
42
+ });
43
+ </script >
Original file line number Diff line number Diff line change @@ -31,6 +31,22 @@ export class OAuthPlugin extends AdminForthPlugin {
31
31
this . adminforth = adminforth ;
32
32
this . resource = resource ;
33
33
34
+ // Add custom page for OAuth callback
35
+ if ( ! adminforth . config . customization . customPages ) {
36
+ adminforth . config . customization . customPages = [ ] ;
37
+ }
38
+
39
+ adminforth . config . customization . customPages . push ( {
40
+ path : '/oauth/callback' ,
41
+ component : {
42
+ file : this . componentPath ( 'OAuthCallback.vue' ) ,
43
+ meta : {
44
+ title : 'OAuth Callback' ,
45
+ customLayout : true
46
+ }
47
+ }
48
+ } ) ;
49
+
34
50
// Validate emailField exists in resource
35
51
if ( ! resource . columns . find ( col => col . name === this . options . emailField ) ) {
36
52
throw new Error ( `OAuthPlugin: emailField "${ this . options . emailField } " not found in resource columns` ) ;
You can’t perform that action at this time.
0 commit comments