Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
useEffect(() => {
const token = getLocalStorageJson('auth.token');
const code = Router.query.code;
if (token) {
setAuthState(authStates.loggedIn);
// TODO: expiry
// const expires = newUser.exp * 1000;
// if (expires <= Date.now()) {
// setAuthState(authStates.expired);
// } else {
// setAuthState(authStates.loggedIn);
// }
} else if (code) {
setAuthState(authStates.authorising);
} else {
setAuthState(authStates.loggedOut);
}
}, []);
function onSuccess(auth) {
const { token } = auth;
if (token == null) return;
setCookie({ token });
// TODO: Typed useRouter.
if (Router.query.redirectUrl) {
Router.replace(Router.query.redirectUrl);
} else if (props.redirectUrl) {
// $FlowFixMe Wrong libdef.
Router.replace(props.redirectUrl);
} else {
// $FlowFixMe Wrong libdef.
Router.replace({
pathname: Router.pathname,
query: Router.query,
});
}
}
function onSuccess(auth) {
const { token } = auth;
if (token == null) return;
setCookie({ token });
// TODO: Typed useRouter.
if (Router.query.redirectUrl) {
Router.replace(Router.query.redirectUrl);
} else if (props.redirectUrl) {
// $FlowFixMe Wrong libdef.
Router.replace(props.redirectUrl);
} else {
// $FlowFixMe Wrong libdef.
Router.replace({
pathname: Router.pathname,
query: Router.query,
});
}
}
Router.onRouteChangeComplete = (url: string) => {
this.setState({
text: Router.query.text,
categories: Router.query.categories.split(','),
});
};
}
dispatch(deleteModification(m._id)).then(() => {
const {projectId, regionId} = Router.query
const {href, as} = routeTo('modifications', {projectId, regionId})
Router.push(href, as)
}),
.catch(() => {
Router.push({
pathname: RouteTo.login,
query: Router.query
})
})
}, [dispatch])
onClick={() =>
Router.push(
{
pathname: Router.route,
query: {
...Router.query,
authModal: 1
}
},
`/auth?continue=${Router.asPath}`,
{ shallow: true }
)
}
.then(() => {
let redirectPath = '/'
this.setState({
error: null
})
if (Router.query.from) {
redirectPath = Router.query['from']
}
Router.push(redirectPath)
})
.catch(err => {
.then(() => {
let redirectPath = '/'
this.setState({
error: null
})
if (Router.query.from) {
redirectPath = Router.query['from']
}
Router.push(redirectPath)
})
.catch(err => {
.then(resp => {
this.setState({ isSubmitting: false })
Router.replace(Router.query.from || '/')
})
})