✨ feat(oauth): Update OAuth login handling to use callback parameter and improve URL parameter retrieval
This commit is contained in:
parent
0aa5d5b0a9
commit
9227411d74
2
apps/admin/services/common/typings.d.ts
vendored
2
apps/admin/services/common/typings.d.ts
vendored
@ -234,7 +234,7 @@ declare namespace API {
|
|||||||
type OAuthLoginGetTokenRequest = {
|
type OAuthLoginGetTokenRequest = {
|
||||||
/** google, facebook, apple, telegram, github etc. */
|
/** google, facebook, apple, telegram, github etc. */
|
||||||
method: string;
|
method: string;
|
||||||
code: string;
|
callback: Record<string, any>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type OAuthLoginResponse = {
|
type OAuthLoginResponse = {
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { oAuthLoginGetToken } from '@/services/common/oauth';
|
import { oAuthLoginGetToken } from '@/services/common/oauth';
|
||||||
import { getRedirectUrl, setAuthorization } from '@/utils/common';
|
import { getAllUrlParams, getRedirectUrl, setAuthorization } from '@/utils/common';
|
||||||
import { useRouter, useSearchParams } from 'next/navigation';
|
import { usePathname, useRouter } from 'next/navigation';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
interface CertificationProps {
|
interface CertificationProps {
|
||||||
@ -11,13 +11,14 @@ interface CertificationProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function Certification({ platform, children }: CertificationProps) {
|
export default function Certification({ platform, children }: CertificationProps) {
|
||||||
const searchParams = useSearchParams();
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const pathname = usePathname();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const searchParams = getAllUrlParams();
|
||||||
oAuthLoginGetToken({
|
oAuthLoginGetToken({
|
||||||
method: platform,
|
method: platform,
|
||||||
code: searchParams.get('code') || '',
|
callback: searchParams,
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const token = res?.data?.data?.token;
|
const token = res?.data?.data?.token;
|
||||||
@ -31,7 +32,7 @@ export default function Certification({ platform, children }: CertificationProps
|
|||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
router.replace('/auth');
|
router.replace('/auth');
|
||||||
});
|
});
|
||||||
}, [platform, searchParams.values()]);
|
}, [pathname]);
|
||||||
|
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|||||||
2
apps/user/services/common/typings.d.ts
vendored
2
apps/user/services/common/typings.d.ts
vendored
@ -234,7 +234,7 @@ declare namespace API {
|
|||||||
type OAuthLoginGetTokenRequest = {
|
type OAuthLoginGetTokenRequest = {
|
||||||
/** google, facebook, apple, telegram, github etc. */
|
/** google, facebook, apple, telegram, github etc. */
|
||||||
method: string;
|
method: string;
|
||||||
code: string;
|
callback: Record<string, any>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type OAuthLoginResponse = {
|
type OAuthLoginResponse = {
|
||||||
|
|||||||
@ -75,3 +75,20 @@ export function getPlatform(): 'windows' | 'mac' | 'linux' | 'android' | 'ios' |
|
|||||||
|
|
||||||
return 'windows';
|
return 'windows';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getAllUrlParams() {
|
||||||
|
const searchParams = new URLSearchParams(window.location.search);
|
||||||
|
const hashParams = new URLSearchParams(window.location.hash.substring(1));
|
||||||
|
|
||||||
|
const params: { [key: string]: string } = {};
|
||||||
|
|
||||||
|
for (const [key, value] of searchParams.entries()) {
|
||||||
|
params[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [key, value] of hashParams.entries()) {
|
||||||
|
params[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user