mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
listening for backend events
This commit is contained in:
parent
2466f01b0b
commit
3ae22fb63d
3 changed files with 24 additions and 8 deletions
|
@ -15,6 +15,8 @@ const mapStateToProps = (state: IState) => selectAuthProfile(state).socials;
|
||||||
const mapDispatchToProps = {
|
const mapDispatchToProps = {
|
||||||
authGetSocials: AUTH_ACTIONS.authGetSocials,
|
authGetSocials: AUTH_ACTIONS.authGetSocials,
|
||||||
authDropSocial: AUTH_ACTIONS.authDropSocial,
|
authDropSocial: AUTH_ACTIONS.authDropSocial,
|
||||||
|
authAttachSocial: AUTH_ACTIONS.authAttachSocial,
|
||||||
|
authSetSocials: AUTH_ACTIONS.authSetSocials,
|
||||||
};
|
};
|
||||||
|
|
||||||
type IProps = ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & {};
|
type IProps = ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & {};
|
||||||
|
@ -27,21 +29,29 @@ const SOCIAL_ICONS: Record<ISocialProvider, string> = {
|
||||||
const ProfileAccountsUnconnected: FC<IProps> = ({
|
const ProfileAccountsUnconnected: FC<IProps> = ({
|
||||||
authGetSocials,
|
authGetSocials,
|
||||||
authDropSocial,
|
authDropSocial,
|
||||||
|
authAttachSocial,
|
||||||
|
authSetSocials,
|
||||||
accounts,
|
accounts,
|
||||||
is_loading,
|
is_loading,
|
||||||
}) => {
|
}) => {
|
||||||
const onMessage = useCallback(event => {
|
const onMessage = useCallback(
|
||||||
// TODO: handle errors
|
(event: MessageEvent) => {
|
||||||
if (event?.data?.type !== 'oauth_attach' || !event?.data?.payload?.token) return;
|
if (!event?.data?.type) return;
|
||||||
|
|
||||||
const token = event?.data?.payload?.token;
|
switch (event?.data?.type) {
|
||||||
|
case 'oauth_processed':
|
||||||
console.log('GOT TOKEN!!!', token);
|
return authAttachSocial(event?.data?.payload?.token);
|
||||||
}, []);
|
case 'oauth_error':
|
||||||
|
return authSetSocials({ error: event?.data?.payload?.error || '' });
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[authAttachSocial, authSetSocials]
|
||||||
|
);
|
||||||
|
|
||||||
const openOauthWindow = useCallback(
|
const openOauthWindow = useCallback(
|
||||||
(provider: ISocialProvider) => () => {
|
(provider: ISocialProvider) => () => {
|
||||||
console.log(API.USER.OAUTH_WINDOW(provider));
|
|
||||||
window.open(API.USER.OAUTH_WINDOW(provider), '', 'width=600,height=400');
|
window.open(API.USER.OAUTH_WINDOW(provider), '', 'width=600,height=400');
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -121,3 +121,8 @@ export const authSetSocials = (socials: Partial<IAuthState['profile']['socials']
|
||||||
type: AUTH_USER_ACTIONS.SET_SOCIALS,
|
type: AUTH_USER_ACTIONS.SET_SOCIALS,
|
||||||
socials,
|
socials,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const authAttachSocial = (token: string) => ({
|
||||||
|
type: AUTH_USER_ACTIONS.ATTACH_SOCIAL,
|
||||||
|
token,
|
||||||
|
});
|
||||||
|
|
|
@ -29,6 +29,7 @@ export const AUTH_USER_ACTIONS = {
|
||||||
DROP_SOCIAL: 'DROP_SOCIAL',
|
DROP_SOCIAL: 'DROP_SOCIAL',
|
||||||
ADD_SOCIAL: 'ADD_SOCIAL',
|
ADD_SOCIAL: 'ADD_SOCIAL',
|
||||||
SET_SOCIALS: 'SET_SOCIALS',
|
SET_SOCIALS: 'SET_SOCIALS',
|
||||||
|
ATTACH_SOCIAL: 'ATTACH_SOCIAL',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const USER_ERRORS = {
|
export const USER_ERRORS = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue