@@ -73,6 +73,7 @@ export default function CollabEditor({
73
73
const [ value , setValue ] = useState ( questionSeed ) ;
74
74
const [ socket , setSocket ] = useState < WebSocket | null > ( null ) ;
75
75
const [ connected , setConnected ] = useState ( false ) ;
76
+ const [ authenticated , setAuthenticated ] = useState ( false ) ;
76
77
const router = useRouter ( ) ;
77
78
78
79
const generatePatch = ( oldContent : string , newContent : string ) : string => {
@@ -157,16 +158,13 @@ export default function CollabEditor({
157
158
newSocket . onmessage = ( event ) => {
158
159
if ( event . data == "Authentication failed" ) {
159
160
window . alert ( "Authentication failed" ) ;
160
- if ( socket ) {
161
- socket . close ( ) ;
162
- }
161
+ newSocket . close ( ) ;
163
162
router . push ( "/questions" ) ;
164
163
} else if ( event . data == "The session has been closed by a user." ) {
165
- window . alert ( "Session has ended" ) ;
166
- if ( socket ) {
167
- socket . close ( ) ;
168
- }
169
- router . push ( "/questions" ) ;
164
+ window . alert ( "Session has ended. If you leave the room now, this data will be lost." ) ;
165
+ newSocket . close ( ) ;
166
+ setAuthenticated ( false ) ;
167
+ setConnected ( false ) ;
170
168
} else {
171
169
const message : Message = JSON . parse ( event . data ) ;
172
170
@@ -221,7 +219,7 @@ export default function CollabEditor({
221
219
222
220
return (
223
221
< >
224
- { connected && (
222
+ { authenticated && (
225
223
< CommsPanel className = "flex flex-row justify-around" roomId = { roomID } />
226
224
) }
227
225
< div className = "m-4 flex items-center space-x-4 p-4" >
0 commit comments