Index: pages/api/poker/index.js
===================================================================
--- pages/api/poker/index.js	(revision 189cd8fbb5d5a78dbc96b7dd32349d209b87bd13)
+++ pages/api/poker/index.js	(revision aac3b2b897972cd33d5372848c2cbac2e4e97ccc)
@@ -47,4 +47,5 @@
             },
         }],
+        onlyOnePlayerLeft: false,
         winners: [],
         splitWinners: false,
@@ -281,5 +282,5 @@
             const { success, table } = getTableAndPlayer(req.query.session_id)
 
-            if (success && !table.started) {
+            if (success && !table.started && !table.ended && table.players.filter(e=>e.isSatDown===true).length >= 2) {
                 table.players.forEach(player => {
                     axios.get(`${process.env.HOME_URL}/api/postgre/?action=check_if_logged_in&session_id=${player.id}`).then(postgreRes => {
@@ -342,6 +343,11 @@
                 player.isFolded = true;
 
-                if (table.players[table.turnIdx] !== undefined && table.players[table.turnIdx] === player) {
-                    setNextPlayerIdx(table.id);
+                if (table.started) {
+                    if (table.players[table.turnIdx] !== undefined && table.players[table.turnIdx] === player) {
+                        setNextPlayerIdx(table.id);
+                    }
+                }
+                else {
+                    table.players = table.players.filter(e=>e.isGhost === false);
                 }
             }
Index: pages/api/poker/tableSpecific.js
===================================================================
--- pages/api/poker/tableSpecific.js	(revision 189cd8fbb5d5a78dbc96b7dd32349d209b87bd13)
+++ pages/api/poker/tableSpecific.js	(revision aac3b2b897972cd33d5372848c2cbac2e4e97ccc)
@@ -62,6 +62,20 @@
     const tableIdx = tables.map(e=>e.id).indexOf(tableId);
 
-    if (tables[tableIdx] !== undefined) {
-        const table = tables[tableIdx];
+    if (tables[tableIdx] !== undefined && !tables[tableIdx].ended) {
+        const table = tables[tableIdx];
+
+        const remainingPlayers = table.players.filter(e=>e.isSatDown===true).filter(e=>e.isGhost===false);
+        if (remainingPlayers.length === 1) {
+            setWinnerDirect(table.id, remainingPlayers[0]);
+
+            return ;
+        }
+
+        const remainingPlayersWithCredits = table.players.filter(e=>e.isSatDown===true).filter(e=>e.isGhost===false).filter(e=>e.isFolded===false).filter(e=>e.credits > 0);
+        if (remainingPlayersWithCredits.length === 1) {
+            progressRoundTillTheEnd(table.id);
+
+            return ;
+        }
 
         if (table.turnTimeout !== null) clearTimeout(table.turnTimeout);
@@ -83,5 +97,5 @@
                         if (table.players[table.turnIdx] !== undefined) {
                             table.players[table.turnIdx].isFolded = true;
-
+                            
                             setNextPlayerIdx(table.id);
                         }
@@ -136,5 +150,5 @@
         table.ended = false;
         table.round = 0;
-        table.turnIdx = 0;
+        table.turnIdx = -1;
         table.turnTimeout = null;
         table.pot = 0;
@@ -143,6 +157,5 @@
         table.deck = [...deck];
 
-        table.players = table.players.filter(e=>e.isGhost === false);
-        table.players = table.players.filter(e=>e.credits >= 20);
+        table.players = table.players.filter(e=>e.isGhost === false).filter(e=>e.credits >= 20);
 
         table.players.forEach(player => {
@@ -157,4 +170,6 @@
             }
         })
+
+        table.onlyOnePlayerLeft = false;
         table.winners = [];
         table.splitWinners = false;
@@ -168,7 +183,4 @@
     if (tables[tableIdx] !== undefined) {
         const table = tables[tableIdx];
-
-        const satDownPlayers = table.players.filter(e => e.isSatDown === true);
-        const satDownCount = satDownPlayers.length;
 
         table.players.forEach(player => {
@@ -212,4 +224,21 @@
 }
 
+export function setWinnerDirect(tableId, player) {
+    const tableIdx = tables.map(e=>e.id).indexOf(tableId);
+
+    if (tables[tableIdx] !== undefined) {
+        const table = tables[tableIdx];
+
+        table.turnIdx = -1;
+        table.started = false;
+        table.ended = true;
+
+        table.onlyOnePlayerLeft = true;
+        table.winners = [player];
+
+        giveMoneyToTheWinners(table.id);
+    }
+}
+
 export function setWinner(tableId) {
     const tableIdx = tables.map(e=>e.id).indexOf(tableId);
@@ -259,4 +288,23 @@
 }
 
+export function progressRoundTillTheEnd(tableId) {
+    const tableIdx = tables.map(e=>e.id).indexOf(tableId);
+
+    if (tables[tableIdx] !== undefined) {
+        const table = tables[tableIdx];
+
+        while (table.round < 4) {
+            table.round++;
+            getCardsOnTable(table.id);
+        }
+
+        table.started = false;
+        table.ended = true;
+        if (table.ended && table.winners.length === 0) {
+            setWinner(table.id);
+        }
+    }
+}
+
 export function progressRoundIfNeeded(tableId) {
     const tableIdx = tables.map(e=>e.id).indexOf(tableId);
@@ -277,4 +325,5 @@
             }
             else {
+                table.started = false;
                 table.ended = true;
             }
Index: pages/api/postgre/index.js
===================================================================
--- pages/api/postgre/index.js	(revision 189cd8fbb5d5a78dbc96b7dd32349d209b87bd13)
+++ pages/api/postgre/index.js	(revision aac3b2b897972cd33d5372848c2cbac2e4e97ccc)
@@ -413,6 +413,7 @@
                     // Already logged in
                     res.json({
-                      success: false,
-                      message: 'You are already logged in',
+                      success: true,
+                      message: 'Login successful',
+                      session: session,
                     })
                   }
