0
Fork 0
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:
simeng-li 2022-05-27 12:46:49 +08:00 committed by GitHub
parent 7015d81378
commit e8ee5b1149
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 14 deletions

View file

@ -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;

View file

@ -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]);
};

View file

@ -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');
});

View file

@ -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);