Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
const response = await axios.get(serverUrl + "/api/token/ping", { headers: { 'Authorization': token } });
// dont really care about response, as long as it not an error
console.log("token ping:", response.data.msg)
} catch (err) {
// in case of error
console.log(err.response.data.msg);
console.log("redirecting back to main page");
// redirect to login
if (ctx.res) {
ctx.res.writeHead(302, {
Location: '/'
})
ctx.res.end()
} else {
Router.push('/')
}
}
}
handleOnURLChange(event, { newValue }) {
const originUrl = { newValue };
this.setState({
url: originUrl.newValue
});
// update the url
const { query } = Router;
query[`url${this.props.id}`] = originUrl.newValue;
const newURL = `${window.location.pathname}?${qs.stringify(query, {
encode: false
})}`;
Router.push(newURL, newURL, { shallow: true });
}
.then(res => {
if (res.error) {
this.setState(
prevState => ({ ...prevState, isLoading: false, error: res.error })
)
return
}
// Redirect
if (this.state.returnUrl) {
Router.push(this.state.returnUrl)
} else {
Router.push('/')
}
})
}
next() {
const { statement, query, error } = this.props
if (error && !query.sequenceNumber) {
console.error(error)
return
}
const to = {
pathname: '/community',
query: {
...query,
sequenceNumber: error
? undefined
: statement && statement.sequenceNumber
}
}
Router.push(to, to, { shallow: true })
}
componentDidMount() {
handleDateSubmit(e) {
e.preventDefault();
const dateProps = this.getDateProps();
Router.push({
pathname: this.props.route.pathname,
query: Object.assign(
{},
removeQueryParams(this.props.route.query, ["after", "before"]),
dateProps,
{
page: 1
}
)
});
}
export default (
ctx,
to = `/profile?next=${encodeURIComponent(
ctx.req ? ctx.req.url : ctx.pathname
)}`
) => {
console.log(ctx)
if (ctx.res) {
ctx.res.writeHead && ctx.res.writeHead(302, { Location: to })
ctx.res.end && ctx.res.end()
return {}
} else {
return Router.push(to)
}
}
handleSignOut = () => {
Cookies.remove('access_token');
Router.push('/');
};
logout = () => {
Router.push(`${LOG_OUT_URL}/logout`);
};
.then(({ data, error }) => {
if (!error) {
this.storeToken(data.token)
this.setState(() => ({
loggedUser: data,
token: data.token,
loginError: error,
authenticated: data.token ? true : false,
}))
Router.push('/')
} else {
this.setState(() => ({
loginError: error.non_field_errors,
}))
}
})
}
componentDidMount() {
logout()
Router.push('/')
}