개인 경로를 인증하려고합니다. 액세스를 허용하기 전에 쿠키를 확인하여 작동하도록했습니다. 그러나 쿠키를 스푸핑하여 쿠키를 허용하고 유효한지 여부를 반환하는 API 끝점을 가질 수 있습니다. API없이API를 사용하여 개인 경로 인증
작업 버전 :
const PrivateRoute = ({ component: Component, ...rest }) => (
<Route {...rest} render={props => (
cookies.get('sessionid') ? (
<Component {...props}/>
) : (
<Redirect to={{
pathname: '/',
state: { from: props.location }
}}/>
)
)}/>
)
ReactDOM.render((
<Router>
<Switch>
<Route exact path="/" component={Login}/>
<PrivateRoute exact path="/home" component={Home} />
<PrivateRoute exact path="/upload" component={Upload}/>
<PrivateRoute exact path="/logout" component={Logout}/>
<PrivateRoute exact path="/review" component={Review}/>
<Route component={ NotFound } />
</Switch>
</Router>
), document.getElementById('root'))
추가 코드 API 호출에 대한 :
axios.post(process.env.REACT_APP_API_URL+'/account/validate-session', {
t1_session_id: cookies.get('sessionid')
})
.then(function (response) {
if(response.data.status === "OK"){
console.log('authenticated go to private route');
} else {
console.log('not valid, redirect to index');
}
}.bind(this))
.catch(function (error) {
console.log('not valid, redirect to index');
}.bind(this));
문제는 내가 주요 도로 구간에 코드의 API 섹션을 통합하는 방법을 모르겠습니다.
감사합니다.