@@ -9,7 +9,7 @@ import { ROOT, exists } from "./filesystem.ts";
9
9
import { loadConfig } from "./config.ts" ;
10
10
import { authUrl , obtainToken } from "./oauth.ts" ;
11
11
import { decodeId } from "./openid.ts" ;
12
- import { getToken , setToken } from "./refresh_tokens.ts" ;
12
+ import { BACKING_FILE , getToken , setToken } from "./refresh_tokens.ts" ;
13
13
14
14
const CONFIG_FILE = "config.json" ;
15
15
@@ -55,20 +55,32 @@ async function handler(request: Request): Promise<Response> {
55
55
56
56
const expiry = new Date ( Date . now ( ) + tokens . expires_in * 1000 ) ;
57
57
const email = decodeId ( tokens . id_token ) . email ;
58
- if ( tokens . refresh_token )
58
+ let newUser = "" ;
59
+ if ( tokens . refresh_token ) {
59
60
await setToken ( email , tokens . refresh_token ) ;
60
- else {
61
+ newUser = " for the first time" ;
62
+ } else {
61
63
const stored = await getToken ( email ) ;
62
- if ( ! stored )
64
+ if ( ! stored ) {
65
+ console . warn ( "User " + email + " missing from " + BACKING_FILE + "!" ) ;
63
66
return new Response (
64
67
"User is banned: " + email ,
65
68
{ status : Status . Forbidden } ,
66
69
) ;
70
+ }
67
71
tokens . refresh_token = stored ;
68
72
}
73
+ console . log ( "User " + email + " logged in" + newUser ) ;
69
74
70
75
let vsCodeToken = emailToToken [ email ] ;
71
- if ( ! vsCodeToken ) {
76
+ if ( vsCodeToken )
77
+ console . log (
78
+ "Reusing user "
79
+ + email
80
+ + "'s existing VSCode instance at port "
81
+ + tokenToPort [ vsCodeToken ]
82
+ ) ;
83
+ else {
72
84
const vscode = Deno . run ( {
73
85
cmd : [ "chroot/jail" , "vscode" , "-c" , "openvscode-drive" ] ,
74
86
stdin : "piped" ,
@@ -83,6 +95,7 @@ async function handler(request: Request): Promise<Response> {
83
95
tokenToPort [ token ] = port ;
84
96
emailToToken [ email ] = token ;
85
97
vsCodeToken = token ;
98
+ console . log ( "Started new VSCode instance for user " + email + " on port " + port ) ;
86
99
}
87
100
url . search = "?tkn=" + vsCodeToken ;
88
101
return Response . redirect ( String ( url ) ) ;
@@ -165,3 +178,4 @@ if(!config) {
165
178
Deno . exit ( 3 ) ;
166
179
}
167
180
serve ( handler , address ) ;
181
+ console . log ( "Started Web server at http://" + address . hostname + ":" + ( address . port ?? 8000 ) ) ;
0 commit comments