Skip to content

Commit 80160a7

Browse files
authored
Merge pull request #2 from devforth/open-signup
Open signup
2 parents 175c78e + b9cdfb4 commit 80160a7

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

custom/OAuthCallback.vue

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,28 @@
77
<script setup>
88
import { onMounted } from 'vue';
99
import { useUserStore } from '@/stores/user';
10-
import { useRouter } from 'vue-router';
10+
import { useRouter, useRoute } from 'vue-router';
1111
import { callAdminForthApi } from '@/utils';
1212
import { Spinner } from '@/afcl';
1313
1414
const router = useRouter();
1515
const userStore = useUserStore();
16+
const route = useRoute();
1617
1718
onMounted(async () => {
1819
const urlParams = new URLSearchParams(window.location.search);
1920
const code = urlParams.get('code');
2021
const state = urlParams.get('state');
21-
const redirectUri = window.location.origin + '/oauth/callback';
22+
23+
const baseUrl = route.meta.baseUrl;
24+
const normalizedBaseUrl = baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`;
25+
const redirectUri = window.location.origin + normalizedBaseUrl + 'oauth/callback';
26+
2227
if (code && state && redirectUri) {
2328
const encodedCode = encodeURIComponent(code);
2429
const encodedState = encodeURIComponent(state);
25-
const encodedRedirectUri = encodeURIComponent(redirectUri);
2630
const response = await callAdminForthApi({
27-
path: `/oauth/callback?code=${encodedCode}&state=${encodedState}&redirect_uri=${encodedRedirectUri}`,
31+
path: `/oauth/callback?code=${encodedCode}&state=${encodedState}&redirect_uri=${redirectUri}`,
2832
method: 'GET',
2933
});
3034
if (response.allowedLogin) {

custom/OAuthLoginButtons.vue

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
meta.pill ? 'rounded-full' : 'rounded-md'
1111
]"
1212
>
13-
<div v-html="provider.icon" class="w-6 h-6" :class="meta.iconOnly ? 'mr-0' : 'mr-4'" :alt="getProviderName(provider.provider)" />
13+
<div v-html="provider.icon" class="w-6 h-6 dark:text-white" :class="meta.iconOnly ? 'mr-0' : 'mr-4'" :alt="getProviderName(provider.provider)" />
1414
<span v-if="!meta.iconOnly" class="font-medium dark:text-white">Continue with {{ getProviderName(provider.provider) }}</span>
1515
</a>
1616
</div>
@@ -29,7 +29,10 @@ const getProviderName = (provider) => {
2929
};
3030
3131
const handleLogin = (authUrl) => {
32-
const redirectUri = window.location.origin + '/oauth/callback';
32+
const baseUrl = props.meta.baseUrl;
33+
const baseUrlSlashed = baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`;
34+
const redirectUri = window.location.origin + baseUrlSlashed + 'oauth/callback';
35+
3336
const url = new URL(authUrl);
3437
url.searchParams.set('redirect_uri', redirectUri);
3538
return url.toString();

index.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ export default class OAuthPlugin extends AdminForthPlugin {
4747

4848
this.adminforth = adminforth;
4949
this.resource = resource;
50-
5150
adminforth.config.customization.customPages.push({
5251
path: '/oauth/callback',
5352
component: {
5453
file: this.componentPath('OAuthCallback.vue'),
5554
meta: {
5655
title: 'OAuth Callback',
57-
customLayout: true
58-
}
56+
customLayout: true,
57+
baseUrl: adminforth.config.baseUrl,
58+
},
5959
}
6060
});
6161

@@ -87,7 +87,6 @@ export default class OAuthPlugin extends AdminForthPlugin {
8787
const componentPath = `@@/plugins/${this.constructor.name}/OAuthLoginButtons.vue`;
8888
this.componentPath('OAuthLoginButtons.vue');
8989

90-
const baseUrl = adminforth.config.baseUrl || '';
9190
const providers = this.options.adapters.map(adapter => {
9291
const state = Buffer.from(JSON.stringify({
9392
provider: adapter.constructor.name
@@ -96,7 +95,6 @@ export default class OAuthPlugin extends AdminForthPlugin {
9695
return {
9796
authUrl: `${adapter.getAuthUrl()}&state=${state}`,
9897
provider: adapter.constructor.name,
99-
baseUrl,
10098
icon: adapter.getIcon(),
10199
};
102100
});
@@ -107,6 +105,7 @@ export default class OAuthPlugin extends AdminForthPlugin {
107105
providers,
108106
iconOnly: this.options.iconOnly,
109107
pill: this.options.pill,
108+
baseUrl: adminforth.config.baseUrl,
110109
}
111110
});
112111
}

0 commit comments

Comments
 (0)