summaryrefslogtreecommitdiff
path: root/animism-align/frontend
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2021-03-05 23:33:50 +0100
committerJules Laplace <julescarbon@gmail.com>2021-03-05 23:33:50 +0100
commitf6e6b1edbbb68bf6bf93a10deebd4cd55ffaff0f (patch)
treebb44de81746cfd088bfab49247b9ec8508bb4605 /animism-align/frontend
parent6726fa9fe050aa47ff7f537b91705372e290f501 (diff)
use other login validator thingie
Diffstat (limited to 'animism-align/frontend')
-rw-r--r--animism-align/frontend/app/api/crud.fetch.js10
-rw-r--r--animism-align/frontend/app/views/auth/auth.actions.js7
-rw-r--r--animism-align/frontend/app/views/auth/auth.gate.js15
-rw-r--r--animism-align/frontend/app/views/auth/auth.reducer.js19
-rw-r--r--animism-align/frontend/app/views/nav/header.component.js2
-rw-r--r--animism-align/frontend/app/views/user/containers/user.edit.js2
-rw-r--r--animism-align/frontend/app/views/user/containers/user.new.js8
7 files changed, 20 insertions, 43 deletions
diff --git a/animism-align/frontend/app/api/crud.fetch.js b/animism-align/frontend/app/api/crud.fetch.js
index a8d4a0d..ddcd80b 100644
--- a/animism-align/frontend/app/api/crud.fetch.js
+++ b/animism-align/frontend/app/api/crud.fetch.js
@@ -55,7 +55,7 @@ export function _get_headers() {
credentials: 'same-origin',
headers: {
'Accept': 'application/json',
- 'Authorization': "JWT " + session.get("access_token"),
+ 'Authorization': "Bearer " + session.get("access_token"),
},
}
}
@@ -66,7 +66,7 @@ export function post(data) {
credentials: 'same-origin',
headers: {
'Accept': 'application/json',
- 'Authorization': "JWT " + session.get("access_token"),
+ 'Authorization': "Bearer " + session.get("access_token"),
'Content-Type': 'application/json'
},
}
@@ -78,7 +78,7 @@ export function postBody(data) {
credentials: 'same-origin',
headers: {
'Accept': 'application/json',
- 'Authorization': "JWT " + session.get("access_token"),
+ 'Authorization': "Bearer " + session.get("access_token"),
},
}
}
@@ -89,7 +89,7 @@ export function put(data) {
credentials: 'same-origin',
headers: {
'Accept': 'application/json',
- 'Authorization': "JWT " + session.get("access_token"),
+ 'Authorization': "Bearer " + session.get("access_token"),
'Content-Type': 'application/json'
},
}
@@ -101,7 +101,7 @@ export function destroy(data) {
credentials: 'same-origin',
headers: {
'Accept': 'application/json',
- 'Authorization': "JWT " + session.get("access_token"),
+ 'Authorization': "Bearer " + session.get("access_token"),
'Content-Type': 'application/json'
},
}
diff --git a/animism-align/frontend/app/views/auth/auth.actions.js b/animism-align/frontend/app/views/auth/auth.actions.js
index fc2a2aa..7eabacc 100644
--- a/animism-align/frontend/app/views/auth/auth.actions.js
+++ b/animism-align/frontend/app/views/auth/auth.actions.js
@@ -20,10 +20,10 @@ export const login = data => dispatch => (
})
.then(req => req.json())
.then(res => {
- if (!res.access_token) {
+ if (!res.token) {
throw new Error(res.description)
}
- session.set('access_token', res.access_token)
+ session.set('access_token', res.token)
load_access_token()(dispatch)
})
)
@@ -32,8 +32,7 @@ export const load_access_token = () => dispatch => {
const access_token = session.get('access_token') || null
if (access_token) {
const creds = jsonwebtoken.decode(access_token)
- const user_id = creds.identity
- return dispatch({ type: types.auth.logged_in, user_id })
+ return dispatch({ type: types.auth.logged_in, user: creds.sub })
} else {
return dispatch({ type: types.auth.logged_out })
}
diff --git a/animism-align/frontend/app/views/auth/auth.gate.js b/animism-align/frontend/app/views/auth/auth.gate.js
index ba69256..36d4af8 100644
--- a/animism-align/frontend/app/views/auth/auth.gate.js
+++ b/animism-align/frontend/app/views/auth/auth.gate.js
@@ -14,23 +14,14 @@ class AuthGate extends Component {
}
componentDidUpdate(prevProps) {
- if (this.props.user_id !== prevProps.user_id) {
+ if (this.props.user.id !== prevProps.user.id) {
this.load()
}
}
load() {
- if (!this.props.user_id) return
- actions.user.show(this.props.user_id)
- .then(() => {
- actions.site.loadProject()
- }).catch(error => {
- if (error.status_code === 401) {
- actions.auth.logout()
- } else {
- console.error(error)
- }
- })
+ if (!this.props.user.id) return
+ actions.site.loadProject()
}
render() {
diff --git a/animism-align/frontend/app/views/auth/auth.reducer.js b/animism-align/frontend/app/views/auth/auth.reducer.js
index 05741f3..8c652ff 100644
--- a/animism-align/frontend/app/views/auth/auth.reducer.js
+++ b/animism-align/frontend/app/views/auth/auth.reducer.js
@@ -3,8 +3,7 @@ import { getDefault } from 'app/session'
const initialState = {
logged_in: !!getDefault('access_token', false),
- user_id: null,
- user: null,
+ user: {},
}
export default function authReducer(state = initialState, action) {
@@ -14,25 +13,13 @@ export default function authReducer(state = initialState, action) {
return {
...state,
logged_in: true,
- user_id: action.user_id,
- user: null,
+ user: action.user,
}
case types.auth.logged_out:
return {
...state,
logged_in: false,
- user_id: null,
- user: null,
- }
- case types.user.show:
- if (action.data.res.id !== state.user_id) {
- return state
- }
- return {
- ...state,
- user: {
- ...action.data.res,
- }
+ user: {},
}
default:
return state
diff --git a/animism-align/frontend/app/views/nav/header.component.js b/animism-align/frontend/app/views/nav/header.component.js
index b264f4d..28be4a7 100644
--- a/animism-align/frontend/app/views/nav/header.component.js
+++ b/animism-align/frontend/app/views/nav/header.component.js
@@ -22,7 +22,7 @@ function Header(props) {
<Link to="/episode">Episodes</Link>
<Link to="/venue">Venues</Link>
<Link to="/viewer">Viewer</Link>
- {props.currentUser.is_admin && <Link to="/user">Users</Link>}
+ {props.currentUser.is_admin && <Link to="/users">Users</Link>}
<a href="#" onClick={actions.auth.logout}>
Logout
</a>
diff --git a/animism-align/frontend/app/views/user/containers/user.edit.js b/animism-align/frontend/app/views/user/containers/user.edit.js
index 5d51792..5ae1fe5 100644
--- a/animism-align/frontend/app/views/user/containers/user.edit.js
+++ b/animism-align/frontend/app/views/user/containers/user.edit.js
@@ -56,6 +56,7 @@ class UserEdit extends Component {
<UserMenu userActions={this.props.userActions} />
<UserForm
data={show.res}
+ currentUser={this.props.currentUser}
onSubmit={this.handleSubmit.bind(this)}
/>
</div>
@@ -65,6 +66,7 @@ class UserEdit extends Component {
const mapStateToProps = state => ({
user: state.user,
+ currentUser: state.auth.user,
})
export default connect(mapStateToProps)(UserEdit)
diff --git a/animism-align/frontend/app/views/user/containers/user.new.js b/animism-align/frontend/app/views/user/containers/user.new.js
index 9d80e0a..01fe1e1 100644
--- a/animism-align/frontend/app/views/user/containers/user.new.js
+++ b/animism-align/frontend/app/views/user/containers/user.new.js
@@ -58,6 +58,7 @@ class UserNew extends Component {
<UserForm
isNew
data={this.state.initialData}
+ currentUser={this.props.currentUser}
onSubmit={this.handleSubmit.bind(this)}
/>
</div>
@@ -67,10 +68,7 @@ class UserNew extends Component {
const mapStateToProps = state => ({
user: state.user,
+ currentUser: state.auth.user,
})
-const mapDispatchToProps = dispatch => ({
- // uploadActions: bindActionCreators({ ...uploadActions }, dispatch),
-})
-
-export default connect(mapStateToProps, mapDispatchToProps)(UserNew)
+export default connect(mapStateToProps)(UserNew)