This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user): add forms for user maangment and forbidden page
- Loading branch information
1 parent
5da4988
commit 5ca4b41
Showing
33 changed files
with
362 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { FORBIDDEN } from 'http-status-codes' | ||
import * as React from 'react' | ||
|
||
import { AppContext } from '@front/domain/AppContext' | ||
|
||
export default class ForbiddenPage extends React.Component { | ||
public static getInitialProps({ res }: AppContext) { | ||
// prettier-ignore | ||
;(res as any).statusCode = FORBIDDEN | ||
|
||
return {} | ||
} | ||
|
||
public render() { | ||
return <p>Forbidden</p> | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
import * as React from 'react' | ||
|
||
import log from '@front/log' | ||
import con from '@shared/module' | ||
import { Landing } from '@front/features/landing' | ||
|
||
import s from './index.css' | ||
|
||
export default () => { | ||
con() | ||
return <p className={s.title}>{log()}</p> | ||
export default class IndexPage extends React.Component { | ||
public render() { | ||
return <Landing /> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as React from 'react' | ||
|
||
export default class AppPage extends React.Component { | ||
public static isSecure = true | ||
|
||
public render() { | ||
return <p>app</p> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as React from 'react' | ||
|
||
export default class HelloPage extends React.Component { | ||
public static isSecure = true | ||
|
||
public render() { | ||
return <p>hello</p> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
const nextRoutes = require('next-routes') | ||
|
||
module.exports = nextRoutes().add('index') | ||
module.exports = nextRoutes() | ||
.add({ pattern: '/', page: 'index' }) | ||
.add({ pattern: '/forbidden', page: 'forbidden' }) | ||
.add({ pattern: '/hello', page: 'internal/hello' }) | ||
.add({ pattern: '/app', page: 'internal/app' }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import axios, { AxiosInstance } from 'axios' | ||
import { Option } from 'tsoption' | ||
|
||
export class Api { | ||
public get client() { | ||
return this.axios | ||
} | ||
|
||
private readonly axios: AxiosInstance | ||
|
||
public constructor(token: Option<string>) { | ||
const authHeaders = token.nonEmpty() | ||
? { Authorization: `Bearer ${token.get()}` } | ||
: {} | ||
|
||
this.axios = axios.create({ | ||
baseURL: 'http://localhost:3000/', | ||
headers: authHeaders, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Option } from 'tsoption' | ||
|
||
import { Api } from './Api' | ||
|
||
export const createApi = (token: Option<string>) => new Api(token) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import { fetchOrFail } from '@front/domain/store/fetchingRedux/fetchOrFail' | ||
|
||
import { signIn as signInRequest } from '../api/signIn' | ||
import { actions as dataActions } from '../reducer/data' | ||
import { actions as signInActions } from '../reducer/signIn' | ||
import { setCookie } from '../setCookie' | ||
|
||
const { setToken } = dataActions | ||
|
||
export const signIn = (login: string, password: string) => | ||
fetchOrFail(signInActions, async dispatch => { | ||
const { token } = { token: `${login}+${password}` } | ||
fetchOrFail(signInActions, async (dispatch, getApi) => { | ||
const { token } = await signInRequest(getApi())(login, password) | ||
|
||
setCookie(token) | ||
|
||
dispatch(setToken(token)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { fetchOrFail } from '@front/domain/store/fetchingRedux/fetchOrFail' | ||
|
||
import { signUp as signUpRequest } from '../api/signUp' | ||
import { actions as dataActions } from '../reducer/data' | ||
import { actions as signUpActions } from '../reducer/signUp' | ||
import { setCookie } from '../setCookie' | ||
|
||
const { setToken } = dataActions | ||
|
||
export const signUp = (login: string, password: string) => | ||
fetchOrFail(signUpActions, async (dispatch, getApi) => { | ||
const { token } = await signUpRequest(getApi())(login, password) | ||
|
||
setCookie(token) | ||
|
||
dispatch(setToken(token)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { TokenModel } from '@shared/models/user/TokenModel' | ||
|
||
import { Api } from '@front/domain/api/Api' | ||
|
||
export const signIn = (api: Api) => ( | ||
email: string, | ||
password: string, | ||
): Promise<TokenModel> => | ||
api.client | ||
.post('user/auth/sign-in', { | ||
email, | ||
password, | ||
}) | ||
.then(response => response.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { TokenModel } from '@shared/models/user/TokenModel' | ||
|
||
import { Api } from '@front/domain/api/Api' | ||
|
||
export const signUp = (api: Api) => ( | ||
email: string, | ||
password: string, | ||
): Promise<TokenModel> => | ||
api.client | ||
.post('user/auth/sign-up', { | ||
email, | ||
password, | ||
}) | ||
.then(response => response.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useCallback } from 'react' | ||
import { useDispatch } from 'redux-react-hook' | ||
|
||
import { signIn } from '@front/domain/user/actions/signIn' | ||
|
||
export const useSignIn = () => { | ||
const dispatch = useDispatch() | ||
|
||
return useCallback( | ||
(login: string, password: string): Promise<any> => | ||
dispatch(signIn(login, password) as any), | ||
[], | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useCallback } from 'react' | ||
import { useDispatch } from 'redux-react-hook' | ||
|
||
import { signUp } from '@front/domain/user/actions/signUp' | ||
|
||
export const useSignUp = () => { | ||
const dispatch = useDispatch() | ||
|
||
return useCallback( | ||
(login: string, password: string): Promise<any> => | ||
dispatch(signUp(login, password) as any), | ||
[], | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { createFetchingStore } from '@front/domain/store/fetchingRedux/createFetchingRedux' | ||
import { FetchingState } from '@front/domain/store/fetchingRedux/FetchingState' | ||
|
||
type State = FetchingState | ||
|
||
const { reducer, actions } = createFetchingStore('user/sign-up') | ||
|
||
export { reducer, actions, State } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { State } from '@front/domain/store/State' | ||
|
||
export const getToken = (state: State) => state.user.data.token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Cookies from 'js-cookie' | ||
|
||
export const setCookie = (token: string) => Cookies.set('token', token) |
Oops, something went wrong.