فهرست منبع

cookie error when session does not exist in the db

sunguroku 5 سال پیش
والد
کامیت
f6fde1900c

+ 1 - 1
dashboard/src/main/Login.tsx

@@ -32,7 +32,7 @@ export default class Login extends Component<PropsType, StateType> {
   componentDidMount() {
     let urlParams = new URLSearchParams(window.location.search);
     let emailFromCLI = urlParams.get('email');
-    emailFromCLI ? this.setState({email: emailFromCLI}) :
+    // emailFromCLI ? this.setState({email: emailFromCLI}) :
     document.addEventListener("keydown", this.handleKeyDown);
   }
 

+ 0 - 1
dashboard/src/main/home/dashboard/expanded-chart/RevisionSection.tsx

@@ -5,7 +5,6 @@ import loading from '../../../../assets/loading.gif';
 import api from '../../../../shared/api';
 import { Context } from '../../../../shared/Context';
 import { ChartType, StorageType } from '../../../../shared/types';
-import Chart from '../chart/Chart';
 
 type PropsType = {
   showRevisions: boolean,

+ 1 - 0
server/api/user_handler.go

@@ -83,6 +83,7 @@ func (app *App) HandleLoginUser(w http.ResponseWriter, r *http.Request) {
 
 	if err != nil {
 		app.handleErrorDataRead(err, w)
+		return
 	}
 
 	form := &forms.LoginUserForm{}

+ 11 - 3
server/router/middleware/auth.go

@@ -3,6 +3,7 @@ package middleware
 import (
 	"bytes"
 	"encoding/json"
+	"fmt"
 	"io/ioutil"
 	"net/http"
 	"strconv"
@@ -28,7 +29,7 @@ func NewAuth(
 // BasicAuthenticate just checks that a user is logged in
 func (auth *Auth) BasicAuthenticate(next http.Handler) http.Handler {
 	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
-		if auth.isLoggedIn(r) {
+		if auth.isLoggedIn(w, r) {
 			next.ServeHTTP(w, r)
 		} else {
 			http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
@@ -95,8 +96,15 @@ func (auth *Auth) doesSessionMatchID(r *http.Request, id uint) bool {
 	return true
 }
 
-func (auth *Auth) isLoggedIn(r *http.Request) bool {
-	session, _ := auth.store.Get(r, auth.cookieName)
+func (auth *Auth) isLoggedIn(w http.ResponseWriter, r *http.Request) bool {
+	session, err := auth.store.Get(r, auth.cookieName)
+	if err != nil {
+		session.Values["authenticated"] = false
+		if err := session.Save(r, w); err != nil {
+			fmt.Println("error while saving session in isLoggedIn", err)
+		}
+		return false
+	}
 
 	if auth, ok := session.Values["authenticated"].(bool); !auth || !ok {
 		return false