mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-04-25 04:09:12 +00:00
45 lines
874 B
JavaScript
45 lines
874 B
JavaScript
import superagent from 'superagent'
|
|
|
|
export const fetchServers = async dispatch => {
|
|
const rsp = await superagent.get('/api/servers')
|
|
|
|
dispatch({
|
|
type: Symbol.for('update servers'),
|
|
data: rsp.body
|
|
})
|
|
|
|
dispatch({
|
|
type: Symbol.for('app ready')
|
|
})
|
|
}
|
|
|
|
export const userInit = async dispatch => {
|
|
if (!window.location.pathname.startsWith('/oauth')) {
|
|
try {
|
|
const rsp = await superagent.get('/api/auth/user')
|
|
|
|
dispatch({
|
|
type: Symbol.for('set user'),
|
|
data: rsp.body
|
|
})
|
|
|
|
dispatch(fetchServers)
|
|
} catch (e) {
|
|
window.location.href = '/oauth/flow'
|
|
}
|
|
} else {
|
|
dispatch({
|
|
type: Symbol.for('app ready')
|
|
})
|
|
}
|
|
}
|
|
|
|
export const userLogout = async dispatch => {
|
|
await superagent.post('/api/auth/logout')
|
|
|
|
dispatch({
|
|
type: Symbol.for('reset user')
|
|
})
|
|
|
|
window.location.href = '/'
|
|
}
|