✨ 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 = {
|
||||
/** google, facebook, apple, telegram, github etc. */
|
||||
method: string;
|
||||
code: string;
|
||||
callback: Record<string, any>;
|
||||
};
|
||||
|
||||
type OAuthLoginResponse = {
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
'use client';
|
||||
|
||||
import { oAuthLoginGetToken } from '@/services/common/oauth';
|
||||
import { getRedirectUrl, setAuthorization } from '@/utils/common';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import { getAllUrlParams, getRedirectUrl, setAuthorization } from '@/utils/common';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
interface CertificationProps {
|
||||
@ -11,13 +11,14 @@ interface CertificationProps {
|
||||
}
|
||||
|
||||
export default function Certification({ platform, children }: CertificationProps) {
|
||||
const searchParams = useSearchParams();
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
|
||||
useEffect(() => {
|
||||
const searchParams = getAllUrlParams();
|
||||
oAuthLoginGetToken({
|
||||
method: platform,
|
||||
code: searchParams.get('code') || '',
|
||||
callback: searchParams,
|
||||
})
|
||||
.then((res) => {
|
||||
const token = res?.data?.data?.token;
|
||||
@ -31,7 +32,7 @@ export default function Certification({ platform, children }: CertificationProps
|
||||
.catch((error) => {
|
||||
router.replace('/auth');
|
||||
});
|
||||
}, [platform, searchParams.values()]);
|
||||
}, [pathname]);
|
||||
|
||||
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 = {
|
||||
/** google, facebook, apple, telegram, github etc. */
|
||||
method: string;
|
||||
code: string;
|
||||
callback: Record<string, any>;
|
||||
};
|
||||
|
||||
type OAuthLoginResponse = {
|
||||
|
||||
@ -75,3 +75,20 @@ export function getPlatform(): 'windows' | 'mac' | 'linux' | 'android' | 'ios' |
|
||||
|
||||
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