@@ -149,7 +149,7 @@ func ExtractAPIKey(rw http.ResponseWriter, r *http.Request, cfg ExtractAPIKeyCon
149
149
// like workspace applications.
150
150
write := func (code int , response codersdk.Response ) (* database.APIKey , * Authorization , bool ) {
151
151
if cfg .RedirectToLogin {
152
- RedirectToLogin (rw , r , response .Message )
152
+ RedirectToLogin (rw , r , nil , response .Message )
153
153
return nil , nil , false
154
154
}
155
155
@@ -440,7 +440,11 @@ func SplitAPIToken(token string) (id string, secret string, err error) {
440
440
441
441
// RedirectToLogin redirects the user to the login page with the `message` and
442
442
// `redirect` query parameters set.
443
- func RedirectToLogin (rw http.ResponseWriter , r * http.Request , message string ) {
443
+ //
444
+ // If dashboardURL is nil, the redirect will be relative to the current
445
+ // request's host. If it is not nil, the redirect will be absolute with dashboard
446
+ // url as the host.
447
+ func RedirectToLogin (rw http.ResponseWriter , r * http.Request , dashboardURL * url.URL , message string ) {
444
448
path := r .URL .Path
445
449
if r .URL .RawQuery != "" {
446
450
path += "?" + r .URL .RawQuery
@@ -454,6 +458,14 @@ func RedirectToLogin(rw http.ResponseWriter, r *http.Request, message string) {
454
458
Path : "/login" ,
455
459
RawQuery : q .Encode (),
456
460
}
461
+ // If dashboardURL is provided, we want to redirect to the dashboard
462
+ // login page.
463
+ if dashboardURL != nil {
464
+ cpy := * dashboardURL
465
+ cpy .Path = u .Path
466
+ cpy .RawQuery = u .RawQuery
467
+ u = & cpy
468
+ }
457
469
458
470
// See other forces a GET request rather than keeping the current method
459
471
// (like temporary redirect does).
0 commit comments