Skip to content

Commit

Permalink
Merge pull request #228 from adrianbielawski/update-login-response
Browse files Browse the repository at this point in the history
Update login and verify email epics to reflect the new response shape.
  • Loading branch information
adrianbielawski authored Sep 12, 2023
2 parents c1de200 + d316b0c commit dc12a7c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
19 changes: 8 additions & 11 deletions src/store/modules/auth-user/epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { retry$ } from 'store/storeObservables'
import * as actions from './slice'
import * as usersActions from 'store/entities/users/slice'
import { User } from 'src/globalTypes'
import { AuthResponse } from './types'
import { typedCombineEpics } from 'store/utils'

export const getUserEpic = (action$: Observable<Action>) =>
Expand Down Expand Up @@ -76,19 +75,19 @@ export const logInEpic = (action$: Observable<Action>) =>
concat(
of(actions.LOG_IN_START()),
axiosInstance$
.post<AuthResponse>('/login/', {
.post<User>('/login/', {
email: action.payload.email,
password: action.payload.password,
})
.pipe(
mergeMap((response) =>
concat(
of(usersActions.USER_ADDED(response.data.user)),
of(actions.LOG_IN_SUCCESS(response.data.user.id)),
of(usersActions.USER_ADDED(response.data)),
of(actions.LOG_IN_SUCCESS(response.data.id)),
defer(() => {
const { pathname } = action.payload.location.state
?.referrer || {
pathname: `/${response.data.user.username}/catalogues`,
pathname: `/${response.data.username}/catalogues`,
}

action.payload.navigate(pathname)
Expand Down Expand Up @@ -146,18 +145,16 @@ export const verifyEmailEpic = (action$: Observable<Action>) =>
filter(actions.VERIFY_EMAIL.match),
mergeMap((action) =>
axiosInstance$
.post<AuthResponse>('/registration/verify-email/', {
.post<User>('/registration/verify-email/', {
key: action.payload.key,
})
.pipe(
mergeMap((response) =>
concat(
of(usersActions.USER_ADDED(response.data.user)),
of(actions.VERIFY_EMAIL_SUCCESS(response.data.user.id)),
of(usersActions.USER_ADDED(response.data)),
of(actions.VERIFY_EMAIL_SUCCESS(response.data.id)),
defer(() => {
action.payload.navigate(
`/${response.data.user.username}/catalogues`,
)
action.payload.navigate(`/${response.data.username}/catalogues`)
return EMPTY
}),
),
Expand Down
7 changes: 1 addition & 6 deletions src/store/modules/auth-user/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorMessage, User } from 'src/globalTypes'
import { ErrorMessage } from 'src/globalTypes'
import { Location, NavigateFunction } from 'react-router-dom'

export interface AuthUserState {
Expand Down Expand Up @@ -49,8 +49,3 @@ export interface VerifyEmailPayload extends NavigateAndLocationPayload {
export interface ChangeUsernamePayload extends NavigateAndLocationPayload {
name: string
}

export interface AuthResponse {
key: string
user: User
}

0 comments on commit dc12a7c

Please sign in to comment.