1
1
package api
2
2
3
3
import (
4
- "github.com/supabase/auth/internal/hooks"
5
- mail "github.com/supabase/auth/internal/mailer"
6
4
"net/http"
7
5
"strings"
8
6
"time"
9
7
8
+ "github.com/supabase/auth/internal/hooks"
9
+ mail "github.com/supabase/auth/internal/mailer"
10
+
10
11
"github.com/badoux/checkmail"
11
12
"github.com/fatih/structs"
12
13
"github.com/pkg/errors"
@@ -123,6 +124,13 @@ func (a *API) adminGenerateLink(w http.ResponseWriter, r *http.Request) error {
123
124
terr = tx .UpdateOnly (user , "recovery_token" , "recovery_sent_at" )
124
125
if terr != nil {
125
126
terr = errors .Wrap (terr , "Database error updating user for recovery" )
127
+ return terr
128
+ }
129
+
130
+ terr = models .CreateOneTimeToken (tx , user .ID , user .GetEmail (), user .RecoveryToken , models .RecoveryToken )
131
+ if terr != nil {
132
+ terr = errors .Wrap (terr , "Database error creating recovery token in admin" )
133
+ return terr
126
134
}
127
135
case mail .InviteVerification :
128
136
if user != nil {
@@ -170,6 +178,12 @@ func (a *API) adminGenerateLink(w http.ResponseWriter, r *http.Request) error {
170
178
terr = tx .UpdateOnly (user , "confirmation_token" , "confirmation_sent_at" , "invited_at" )
171
179
if terr != nil {
172
180
terr = errors .Wrap (terr , "Database error updating user for invite" )
181
+ return terr
182
+ }
183
+ terr = models .CreateOneTimeToken (tx , user .ID , user .GetEmail (), user .ConfirmationToken , models .ConfirmationToken )
184
+ if terr != nil {
185
+ terr = errors .Wrap (terr , "Database error creating confirmation token for invite in admin" )
186
+ return terr
173
187
}
174
188
case mail .SignupVerification :
175
189
if user != nil {
@@ -202,6 +216,12 @@ func (a *API) adminGenerateLink(w http.ResponseWriter, r *http.Request) error {
202
216
terr = tx .UpdateOnly (user , "confirmation_token" , "confirmation_sent_at" )
203
217
if terr != nil {
204
218
terr = errors .Wrap (terr , "Database error updating user for confirmation" )
219
+ return terr
220
+ }
221
+ terr = models .CreateOneTimeToken (tx , user .ID , user .GetEmail (), user .ConfirmationToken , models .ConfirmationToken )
222
+ if terr != nil {
223
+ terr = errors .Wrap (terr , "Database error creating confirmation token for signup in admin" )
224
+ return terr
205
225
}
206
226
case mail .EmailChangeCurrentVerification , mail .EmailChangeNewVerification :
207
227
if ! config .Mailer .SecureEmailChangeEnabled && params .Type == "email_change_current" {
@@ -228,6 +248,21 @@ func (a *API) adminGenerateLink(w http.ResponseWriter, r *http.Request) error {
228
248
terr = tx .UpdateOnly (user , "email_change_token_current" , "email_change_token_new" , "email_change" , "email_change_sent_at" , "email_change_confirm_status" )
229
249
if terr != nil {
230
250
terr = errors .Wrap (terr , "Database error updating user for email change" )
251
+ return terr
252
+ }
253
+ if user .EmailChangeTokenCurrent != "" {
254
+ terr = models .CreateOneTimeToken (tx , user .ID , user .GetEmail (), user .EmailChangeTokenCurrent , models .EmailChangeTokenCurrent )
255
+ if terr != nil {
256
+ terr = errors .Wrap (terr , "Database error creating email change token current in admin" )
257
+ return terr
258
+ }
259
+ }
260
+ if user .EmailChangeTokenNew != "" {
261
+ terr = models .CreateOneTimeToken (tx , user .ID , user .EmailChange , user .EmailChangeTokenNew , models .EmailChangeTokenNew )
262
+ if terr != nil {
263
+ terr = errors .Wrap (terr , "Database error creating email change token new in admin" )
264
+ return terr
265
+ }
231
266
}
232
267
default :
233
268
return badRequestError (ErrorCodeValidationFailed , "Invalid email action link type requested: %v" , params .Type )
@@ -290,6 +325,11 @@ func (a *API) sendConfirmation(r *http.Request, tx *storage.Connection, u *model
290
325
return errors .Wrap (err , "Database error updating user for confirmation" )
291
326
}
292
327
328
+ err = models .CreateOneTimeToken (tx , u .ID , u .GetEmail (), u .ConfirmationToken , models .ConfirmationToken )
329
+ if err != nil {
330
+ return errors .Wrap (err , "Database error creating confirmation token" )
331
+ }
332
+
293
333
return nil
294
334
}
295
335
@@ -317,6 +357,11 @@ func (a *API) sendInvite(r *http.Request, tx *storage.Connection, u *models.User
317
357
return errors .Wrap (err , "Database error updating user for invite" )
318
358
}
319
359
360
+ err = models .CreateOneTimeToken (tx , u .ID , u .GetEmail (), u .ConfirmationToken , models .ConfirmationToken )
361
+ if err != nil {
362
+ return errors .Wrap (err , "Database error creating confirmation token for invite" )
363
+ }
364
+
320
365
return nil
321
366
}
322
367
@@ -349,6 +394,11 @@ func (a *API) sendPasswordRecovery(r *http.Request, tx *storage.Connection, u *m
349
394
return errors .Wrap (err , "Database error updating user for recovery" )
350
395
}
351
396
397
+ err = models .CreateOneTimeToken (tx , u .ID , u .GetEmail (), u .RecoveryToken , models .RecoveryToken )
398
+ if err != nil {
399
+ return errors .Wrap (err , "Database error creating recovery token" )
400
+ }
401
+
352
402
return nil
353
403
}
354
404
@@ -381,6 +431,11 @@ func (a *API) sendReauthenticationOtp(r *http.Request, tx *storage.Connection, u
381
431
return errors .Wrap (err , "Database error updating user for reauthentication" )
382
432
}
383
433
434
+ err = models .CreateOneTimeToken (tx , u .ID , u .GetEmail (), u .ReauthenticationToken , models .ReauthenticationToken )
435
+ if err != nil {
436
+ return errors .Wrap (err , "Database error creating reauthentication token" )
437
+ }
438
+
384
439
return nil
385
440
}
386
441
@@ -416,6 +471,11 @@ func (a *API) sendMagicLink(r *http.Request, tx *storage.Connection, u *models.U
416
471
return errors .Wrap (err , "Database error updating user for recovery" )
417
472
}
418
473
474
+ err = models .CreateOneTimeToken (tx , u .ID , u .GetEmail (), u .RecoveryToken , models .RecoveryToken )
475
+ if err != nil {
476
+ return errors .Wrap (err , "Database error creating recovery token" )
477
+ }
478
+
419
479
return nil
420
480
}
421
481
@@ -469,6 +529,20 @@ func (a *API) sendEmailChange(r *http.Request, tx *storage.Connection, u *models
469
529
return errors .Wrap (err , "Database error updating user for email change" )
470
530
}
471
531
532
+ if u .EmailChangeTokenCurrent != "" {
533
+ err = models .CreateOneTimeToken (tx , u .ID , u .GetEmail (), u .EmailChangeTokenCurrent , models .EmailChangeTokenCurrent )
534
+ if err != nil {
535
+ return errors .Wrap (err , "Database error creating email change token current" )
536
+ }
537
+ }
538
+
539
+ if u .EmailChangeTokenNew != "" {
540
+ err = models .CreateOneTimeToken (tx , u .ID , u .EmailChange , u .EmailChangeTokenNew , models .EmailChangeTokenNew )
541
+ if err != nil {
542
+ return errors .Wrap (err , "Database error creating email change token new" )
543
+ }
544
+ }
545
+
472
546
return nil
473
547
}
474
548
0 commit comments