Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade deps #28

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 68 additions & 54 deletions authentication/epic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { combineEpics } = require('redux-observable')
const Rx = require('rxjs')
const { combineEpics, ofType } = require('redux-observable')
const { Observable, of, concat: indexConcat, from, empty, merge: indexMerge } = require('rxjs')
const { delay, switchMap, mergeMap, catchError, concat, filter, take, withLatestFrom, map, mapTo } = require('rxjs/operators')
const createCid = require('incremental-id')
const { push } = require('react-router-redux')

Expand All @@ -15,112 +16,125 @@ const {
module.exports = combineEpics(initEpic, signInEpic, logOutEpic, registerEpic)

exports.initEpic = initEpic
function initEpic () {
return Rx.Observable.of(signIn(createCid()))
.delay(0) // apparently needs delay otherwise action lost
function initEpic (action$) {
return of(signIn(createCid()))
// .pipe(
// delay(0) // apparently needs delay otherwise action lost
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we sure about removing this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no i am not sure 😅 everything seems to be working without it, i see the SIGN_IN actions i expect to see, but perhaps you have more context there @ahdinosaur ?

Copy link
Member

@ahdinosaur ahdinosaur Jul 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// )
}

exports.signInEpic = signInEpic
function signInEpic (action$, store, { feathers }) {
return action$.ofType(signIn.type)
.switchMap(({ payload, meta: { cid } }) => Rx.Observable.concat(
Rx.Observable.of(signInStart(cid)),
Rx.Observable.fromPromise(
return action$.pipe(
ofType(signIn.type),
switchMap(({ payload, meta: { cid } }) => indexConcat(
of(signInStart(cid)),
from(
feathers.authenticate(payload)
.then(({ accessToken }) => {
return feathers.passport.verifyJWT(accessToken)
.then(({ credentialId }) => {
return { accessToken, credentialId }
})
})
)
.mergeMap(({ accessToken, credentialId }) => {
return Rx.Observable.concat(
Rx.Observable.of(signInSuccess(cid, { accessToken, credentialId })),
).pipe(
mergeMap(({ accessToken, credentialId }) => {
return indexConcat(
of(signInSuccess(cid, { accessToken, credentialId })),
fetchAgentByCredential(action$, cid, credentialId)
)
})
//.mergeMap(actions => Rx.Observable.of(...actions))
}),
// mergeMap(actions => of(...actions))
// can't swallow error as part of promise chain
// because we want to not emit an action, rather than undefined.
.catch((err) => {
catchError((err) => {
// if init signIn() fails, it's not an error
if (err.message === 'Could not find stored JWT and no authentication strategy was given') return Rx.Observable.empty()
return Rx.Observable.of(signInError(cid, err))
if (err.message === 'Could not find stored JWT and no authentication strategy was given') return empty()
return of(signInError(cid, err))
})
)
))
)
}

exports.logOutEpic = logOutEpic
function logOutEpic (action$, store, { feathers }) {
return action$.ofType(logOut.type)
.switchMap(({ meta: { cid } }) => Rx.Observable.concat(
Rx.Observable.of(logOutStart(cid)),
Rx.Observable.fromPromise(
return action$.pipe(
ofType(logOut.type),
switchMap(({ meta: { cid } }) => indexConcat(
of(logOutStart(cid)),
from(
feathers.logout()
.then(() => logOutSuccess(cid))
).pipe(
concat(of(push('/'))), // TODO this should be configurable
catchError((err) => of(logOutError(cid, err)))
)
.concat(Rx.Observable.of(push('/'))) // TODO this should be configurable
.catch((err) => Rx.Observable.of(logOutError(cid, err)))
))
)
}

exports.registerEpic = registerEpic
function registerEpic (action$, store, deps) {
return action$.ofType(register.type)
.switchMap(action => {
return action$.pipe(
ofType(register.type),
switchMap(action => {
const { payload } = action
const { email, password, name } = payload
const { cid } = action.meta

const createdSuccess$ = action$.ofType(credentials.complete.type).filter(onlyCid).take(1)
const createdError$ = action$.ofType(credentials.error.type).filter(onlyCid).take(1)
const createdSuccess$ = action$.pipe(ofType(credentials.complete.type), filter(onlyCid), take(1))
const createdError$ = action$.pipe(ofType(credentials.error.type), filter(onlyCid), take(1))
// get only the last set item, since it should be the latest
const createdSet$ = action$.ofType(credentials.set.type).filter(onlyCid)
const signInSuccess$ = action$.ofType(signInSuccess.type).filter(onlyCid).take(1)
const createdSet$ = action$.pipe(ofType(credentials.set.type), filter(onlyCid))
const signInSuccess$ = action$.pipe(ofType(signInSuccess.type), filter(onlyCid), take(1))

// TODO create initial profile with name
return Rx.Observable.merge(
Rx.Observable.of(
return indexMerge(
of(
registerStart(cid),
credentials.create(cid, { email, password, name })
),
createdSuccess$
.withLatestFrom(createdSet$, (success, set) => set.payload.data)
.mergeMap(created => {
return Rx.Observable.of(
createdSuccess$.pipe(
withLatestFrom(createdSet$, (success, set) => set.payload.data),
mergeMap(created => {
return of(
registerSuccess(cid, created),
signIn(cid, { strategy: 'local', email, password })
)
}),
createdError$.map(action => registerError(cid, action.payload)),
signInSuccess$.mapTo(push('/')) // TODO this should be configurable
})
),
createdError$.pipe(map(action => registerError(cid, action.payload))),
signInSuccess$.pipe(mapTo(push('/'))) // TODO this should be configurable
)

function onlyCid (action) {
return action.meta.cid === cid
}
})
)
}


function fetchAgentByCredential (action$, cid, credentialId) {
const agentSet$ = action$.ofType(agents.set.type).filter(onlyCid)
const credentialSet$ = action$.ofType(credentials.set.type).filter(onlyCid)
const profileSet$ = action$.ofType(profiles.set.type).filter(onlyCid)
const agentSet$ = action$.pipe(ofType(agents.set.type), filter(onlyCid))
const credentialSet$ = action$.pipe(ofType(credentials.set.type), filter(onlyCid))
const profileSet$ = action$.pipe(ofType(profiles.set.type), filter(onlyCid))

return Rx.Observable.merge(
Rx.Observable.of(credentials.get(cid, credentialId)),
credentialSet$.mergeMap(action => {
const { agentId } = action.payload.data
return Rx.Observable.of(
credentials.complete(cid),
agents.get(cid, agentId),
profiles.find(cid, { query: { agentId } })
)
}),
profileSet$.map(() => profiles.complete(cid)),
agentSet$.map(() => agents.complete(cid))
return indexMerge(
of(credentials.get(cid, credentialId)),
credentialSet$.pipe(
mergeMap(action => {
const { agentId } = action.payload.data
return of(
credentials.complete(cid),
agents.get(cid, agentId),
profiles.find(cid, { query: { agentId } })
)
})
),
profileSet$.pipe(map(() => profiles.complete(cid))),
agentSet$.pipe(map(() => agents.complete(cid)))
)

function onlyCid (action) {
Expand Down
8 changes: 4 additions & 4 deletions authentication/service.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { keys, assign } = Object
const assert = require('assert')
const authentication = require('feathers-authentication')
const authentication = require('@feathersjs/authentication')
const { authenticate } = authentication.hooks
const local = require('feathers-authentication-local')
const jwt = require('feathers-authentication-jwt')
const oauth2 = require('feathers-authentication-oauth2')
const local = require('@feathersjs/authentication-local')
const jwt = require('@feathersjs/authentication-jwt')
const oauth2 = require('@feathersjs/authentication-oauth2')

const remotePlugins = { oauth2 }

Expand Down
2 changes: 1 addition & 1 deletion client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const auth = require('feathers-authentication-client')
const auth = require('@feathersjs/authentication-client')

module.exports = function () {
const app = this
Expand Down
2 changes: 1 addition & 1 deletion credentials/service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const feathersKnex = require('feathers-knex')
const { hashPassword } = require('feathers-authentication-local').hooks
const { hashPassword } = require('@feathersjs/authentication-local').hooks
const { isProvider: isTransport, iff, discard } = require('feathers-hooks-common')
const isNil = require('ramda/src/isNil')

Expand Down
Loading