MCPcopy Create free account
hub / github.com/netlify/gotrue / Verify

Method Verify

api/verify.go:25–78  ·  view source on GitHub ↗

Verify exchanges a confirmation or recovery token to a refresh token

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

23
24// Verify exchanges a confirmation or recovery token to a refresh token
25func (a *API) Verify(w http.ResponseWriter, r *http.Request) error {
26 ctx := r.Context()
27 config := a.getConfig(ctx)
28
29 params := &VerifyParams{}
30 cookie := r.Header.Get(useCookieHeader)
31 jsonDecoder := json.NewDecoder(r.Body)
32 if err := jsonDecoder.Decode(params); err != nil {
33 return badRequestError("Could not read verification params: %v", err)
34 }
35
36 if params.Token == "" {
37 return unprocessableEntityError("Verify requires a token")
38 }
39
40 var (
41 user *models.User
42 err error
43 token *AccessTokenResponse
44 )
45
46 err = a.db.Transaction(func(tx *storage.Connection) error {
47 var terr error
48 switch params.Type {
49 case signupVerification:
50 user, terr = a.signupVerify(ctx, tx, params)
51 case recoveryVerification:
52 user, terr = a.recoverVerify(ctx, tx, params)
53 default:
54 return unprocessableEntityError("Verify requires a verification type")
55 }
56
57 if terr != nil {
58 return terr
59 }
60
61 token, terr = a.issueRefreshToken(ctx, tx, user)
62 if terr != nil {
63 return terr
64 }
65
66 if cookie != "" && config.Cookie.Duration > 0 {
67 if terr = a.setCookieToken(config, token.Token, cookie == useSessionCookie, w); terr != nil {
68 return internalServerError("Failed to set JWT cookie. %s", terr)
69 }
70 }
71 return nil
72 })
73 if err != nil {
74 return err
75 }
76
77 return sendJSON(w, http.StatusOK, token)
78}
79
80func (a *API) signupVerify(ctx context.Context, conn *storage.Connection, params *VerifyParams) (*models.User, error) {
81 instanceID := getInstanceID(ctx)

Callers

nothing calls this directly

Calls 11

getConfigMethod · 0.95
signupVerifyMethod · 0.95
recoverVerifyMethod · 0.95
issueRefreshTokenMethod · 0.95
setCookieTokenMethod · 0.95
badRequestErrorFunction · 0.85
unprocessableEntityErrorFunction · 0.85
internalServerErrorFunction · 0.85
sendJSONFunction · 0.85
GetMethod · 0.80
TransactionMethod · 0.80

Tested by

no test coverage detected