mirror of
https://github.com/logto-io/logto.git
synced 2025-01-20 21:32:31 -05:00
refactor(ui): refactor social sign-in code flow (#969)
* refactor(ui): refactor social signin callback flow refactor social signin callback flow * fix(ui): change file structure change file structure * refactor(ui): refactor social sign-in code flow refactor social sign-in code flow
This commit is contained in:
parent
7015d81378
commit
e8ee5b1149
4 changed files with 7 additions and 14 deletions
|
@ -14,7 +14,7 @@ const useSocialCallbackHandler = () => {
|
|||
const navigate = useNavigate();
|
||||
|
||||
const socialCallbackHandler = useCallback(() => {
|
||||
const { state, code, error, error_description } = parseQueryParameters(window.location.search);
|
||||
const { state, error, error_description } = parseQueryParameters(window.location.search);
|
||||
const connectorId = parameters.connector;
|
||||
|
||||
// Connector auth error
|
||||
|
@ -23,7 +23,7 @@ const useSocialCallbackHandler = () => {
|
|||
}
|
||||
|
||||
// Connector auth missing state
|
||||
if (!state || !code || !connectorId) {
|
||||
if (!state || !connectorId) {
|
||||
setToast(t('error.missing_auth_data'));
|
||||
|
||||
return;
|
||||
|
|
|
@ -41,7 +41,7 @@ const useSocialSignInListener = () => {
|
|||
void asyncSignInWithSocial({
|
||||
connectorId,
|
||||
code,
|
||||
redirectUri: `${origin}/callback/${connectorId}`, // For validation use only
|
||||
redirectUri: `${window.location.origin}/callback/${connectorId}`, // For validation use only
|
||||
});
|
||||
},
|
||||
[asyncSignInWithSocial]
|
||||
|
@ -59,19 +59,15 @@ const useSocialSignInListener = () => {
|
|||
return;
|
||||
}
|
||||
|
||||
const { state, code } = parseQueryParameters(window.location.search);
|
||||
const { state, code, ...rest } = parseQueryParameters(window.location.search);
|
||||
|
||||
if (!state || !code) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!stateValidation(state, parameters.connector)) {
|
||||
if (!state || !stateValidation(state, parameters.connector)) {
|
||||
setToast(t('error.invalid_connector_auth'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void signInWithSocialHandler(parameters.connector, state, code);
|
||||
void signInWithSocialHandler(parameters.connector, state, code ?? JSON.stringify(rest));
|
||||
}, [parameters.connector, setToast, signInWithSocialHandler, t]);
|
||||
};
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ describe('util methods', () => {
|
|||
});
|
||||
|
||||
it('queryStringify', () => {
|
||||
expect(queryStringify('foo=test')).toEqual('foo=test');
|
||||
expect(queryStringify(new URLSearchParams({ foo: 'test' }))).toEqual('foo=test');
|
||||
});
|
||||
|
||||
|
|
|
@ -10,9 +10,7 @@ export const parseQueryParameters = (parameters: string | URLSearchParams) => {
|
|||
return Object.fromEntries(searchParameters.entries());
|
||||
};
|
||||
|
||||
export const queryStringify = (
|
||||
parameters: string | URLSearchParams | Record<string, string | string>
|
||||
) => {
|
||||
export const queryStringify = (parameters: URLSearchParams | Record<string, string>) => {
|
||||
const searchParameters =
|
||||
parameters instanceof URLSearchParams ? parameters : new URLSearchParams(parameters);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue