improve (login): redirect the user to the login screen once the session expire

This commit is contained in:
Mickael KERJEAN 2019-03-08 01:25:29 +11:00
parent 7f8c47c186
commit a02510418d
4 changed files with 15 additions and 1 deletions

View file

@ -98,6 +98,9 @@ class FileSystem{
return store;
});
}).catch((_err) => {
if(_err.code === "Unauthorized"){
location = "/login?next="+location.pathname;
}
this.obs.next(_err);
return Promise.reject(null);
});

View file

@ -23,7 +23,10 @@ export class ConnectPage extends React.Component {
componentWillMount(){
const urlData = urlParams();
if(Object.keys(urlData).length === 0){
const get_params = Object.keys(urlData);
if(get_params.length === 0){
return;
}else if(get_params.length === 1 && !!urlData["next"]){
return;
}
@ -40,6 +43,9 @@ export class ConnectPage extends React.Component {
Session.authenticate(params)
.then(Session.currentUser)
.then((user) => {
if(location.search.indexOf("?next=") === 0){
location = urlParams()["next"];
}
let url = '/files/';
let path = user.home;
if(path){

View file

@ -19,6 +19,7 @@ var (
ErrNotImplemented = NewError("Not Implemented", 501)
ErrFilesystemError = NewError("Can't use filesystem", 503)
ErrMissingDependency = NewError("Missing dependency", 424)
ErrNotAuthorized = NewError("Not authorized", 401)
)
type AppError struct {

View file

@ -59,6 +59,10 @@ func SessionStart (fn func(App, http.ResponseWriter, *http.Request)) func(ctx Ap
return
}
if ctx.Backend, err = _extractBackend(req, &ctx); err != nil {
if len(ctx.Session) == 0 {
SendErrorResult(res, ErrNotAuthorized)
return
}
SendErrorResult(res, err)
return
}