Skip to content

Commit 6e89720

Browse files
Merge pull request #212 from supertokens/new-apis-dashboard
feat: Add new apis for dashboard recipe
2 parents c838899 + 2aab3c4 commit 6e89720

File tree

27 files changed

+1724
-47
lines changed

27 files changed

+1724
-47
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
## [0.9.9] - 2022-11-24
11+
12+
### Added:
13+
- Adds APIs for user details to the dashboard recipe
14+
15+
### Changed:
16+
- Updates dashboard version to 0.2
17+
1018
## [0.9.8] - 2022-11-16
1119
- Fixes go fiber to handle handler chaining correctly with verifySession.
1220
- Added test to check JWT contains updated value when MergeIntoAccessTokenPayload is called.

examples/go.sum

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
214214
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
215215
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
216216
github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8=
217-
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
218217
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
219218
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
220219
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@@ -424,7 +423,6 @@ github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uY
424423
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
425424
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
426425
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
427-
github.com/nyaruka/phonenumbers v1.0.73 h1:bP2WN8/NUP8tQebR+WCIejFaibwYMHOaB7MQVayclUo=
428426
github.com/nyaruka/phonenumbers v1.0.73/go.mod h1:3aiS+PS3DuYwkbK3xdcmRwMiPNECZ0oENH8qUT1lY7Q=
429427
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
430428
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
@@ -544,7 +542,6 @@ github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69
544542
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
545543
github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk=
546544
github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ=
547-
github.com/twilio/twilio-go v0.26.0 h1:wFW4oTe3/LKt6bvByP7eio8JsjtaLHjMQKOUEzQry7U=
548545
github.com/twilio/twilio-go v0.26.0/go.mod h1:lz62Hopu4vicpQ056H5TJ0JE4AP0rS3sQ35/ejmgOwE=
549546
github.com/twitchtv/twirp v8.1.0+incompatible h1:KGXanpa9LXdVE/V5P/tA27rkKFmXRGCtSNT7zdeeVOY=
550547
github.com/twitchtv/twirp v8.1.0+incompatible/go.mod h1:RRJoFSAmTEh2weEqWtpPE3vFK5YBhA6bqp2l1kfCC5A=
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved.
2+
*
3+
* This software is licensed under the Apache License, Version 2.0 (the
4+
* "License") as published by the Apache Software Foundation.
5+
*
6+
* You may not use this file except in compliance with the License. You may
7+
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and limitations
13+
* under the License.
14+
*/
15+
16+
package userdetails
17+
18+
import (
19+
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
20+
"github.com/supertokens/supertokens-golang/supertokens"
21+
)
22+
23+
type userDeleteResponse struct {
24+
Status string `json:"status"`
25+
}
26+
27+
func UserDelete(apiInterface dashboardmodels.APIInterface, options dashboardmodels.APIOptions) (userDeleteResponse, error) {
28+
req := options.Req
29+
userId := req.URL.Query().Get("userId")
30+
31+
if userId == "" {
32+
return userDeleteResponse{}, supertokens.BadInputError{
33+
Msg: "Missing required parameter 'userId'",
34+
}
35+
}
36+
37+
deleteError := supertokens.DeleteUser(userId)
38+
39+
if deleteError != nil {
40+
return userDeleteResponse{}, deleteError
41+
}
42+
43+
return userDeleteResponse{
44+
Status: "OK",
45+
}, nil
46+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved.
2+
*
3+
* This software is licensed under the Apache License, Version 2.0 (the
4+
* "License") as published by the Apache Software Foundation.
5+
*
6+
* You may not use this file except in compliance with the License. You may
7+
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and limitations
13+
* under the License.
14+
*/
15+
16+
package userdetails
17+
18+
import (
19+
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
20+
"github.com/supertokens/supertokens-golang/recipe/emailverification"
21+
"github.com/supertokens/supertokens-golang/supertokens"
22+
)
23+
24+
type userEmailVerifyGetResponse struct {
25+
Status string `json:"status"`
26+
IsVerified *bool `json:"isVerified,omitempty"`
27+
}
28+
29+
func UserEmailVerifyGet(apiImplementation dashboardmodels.APIInterface, options dashboardmodels.APIOptions) (userEmailVerifyGetResponse, error) {
30+
req := options.Req
31+
userId := req.URL.Query().Get("userId")
32+
33+
if userId == "" {
34+
return userEmailVerifyGetResponse{}, supertokens.BadInputError{
35+
Msg: "Missing required parameter 'userId'",
36+
}
37+
}
38+
39+
emailverificationInstance := emailverification.GetRecipeInstance()
40+
41+
if emailverificationInstance == nil {
42+
return userEmailVerifyGetResponse{
43+
Status: "FEATURE_NOT_ENABLED_ERROR",
44+
}, nil
45+
}
46+
47+
response, verificationError := emailverification.IsEmailVerified(userId, nil)
48+
49+
if verificationError != nil {
50+
return userEmailVerifyGetResponse{}, verificationError
51+
}
52+
53+
return userEmailVerifyGetResponse{
54+
Status: "OK",
55+
IsVerified: &response,
56+
}, nil
57+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved.
2+
*
3+
* This software is licensed under the Apache License, Version 2.0 (the
4+
* "License") as published by the Apache Software Foundation.
5+
*
6+
* You may not use this file except in compliance with the License. You may
7+
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and limitations
13+
* under the License.
14+
*/
15+
16+
package userdetails
17+
18+
import (
19+
"encoding/json"
20+
"errors"
21+
22+
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
23+
"github.com/supertokens/supertokens-golang/recipe/emailverification"
24+
"github.com/supertokens/supertokens-golang/supertokens"
25+
)
26+
27+
type userEmailVerifyPutResponse struct {
28+
Status string `json:"status"`
29+
}
30+
31+
type userEmailVerifyPutRequestBody struct {
32+
UserID *string `json:"userId"`
33+
Verified *bool `json:"verified"`
34+
}
35+
36+
func UserEmailVerifyPut(apiInterface dashboardmodels.APIInterface, options dashboardmodels.APIOptions) (userEmailVerifyPutResponse, error) {
37+
body, err := supertokens.ReadFromRequest(options.Req)
38+
39+
if err != nil {
40+
return userEmailVerifyPutResponse{}, err
41+
}
42+
43+
var readBody userEmailVerifyPutRequestBody
44+
err = json.Unmarshal(body, &readBody)
45+
if err != nil {
46+
return userEmailVerifyPutResponse{}, err
47+
}
48+
49+
if readBody.UserID == nil {
50+
return userEmailVerifyPutResponse{}, supertokens.BadInputError{
51+
Msg: "Required parameter 'userId' is missing",
52+
}
53+
}
54+
55+
if readBody.Verified == nil {
56+
return userEmailVerifyPutResponse{}, supertokens.BadInputError{
57+
Msg: "Required parameter 'verified' is missing",
58+
}
59+
}
60+
61+
if *readBody.Verified {
62+
tokenResponse, tokenErr := emailverification.CreateEmailVerificationToken(*readBody.UserID, nil)
63+
64+
if tokenErr != nil {
65+
return userEmailVerifyPutResponse{}, tokenErr
66+
}
67+
68+
if tokenResponse.EmailAlreadyVerifiedError != nil {
69+
return userEmailVerifyPutResponse{
70+
Status: "OK",
71+
}, nil
72+
}
73+
74+
verifyResponse, verifyErr := emailverification.VerifyEmailUsingToken(tokenResponse.OK.Token)
75+
76+
if verifyErr != nil {
77+
return userEmailVerifyPutResponse{}, verifyErr
78+
}
79+
80+
// It should never come here because we generate the token immediately before this step
81+
if verifyResponse.EmailVerificationInvalidTokenError != nil {
82+
return userEmailVerifyPutResponse{}, errors.New("Should never come here")
83+
}
84+
} else {
85+
_, unverifyErr := emailverification.UnverifyEmail(*readBody.UserID, nil)
86+
87+
if unverifyErr != nil {
88+
return userEmailVerifyPutResponse{}, unverifyErr
89+
}
90+
}
91+
92+
return userEmailVerifyPutResponse{
93+
Status: "OK",
94+
}, nil
95+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved.
2+
*
3+
* This software is licensed under the Apache License, Version 2.0 (the
4+
* "License") as published by the Apache Software Foundation.
5+
*
6+
* You may not use this file except in compliance with the License. You may
7+
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and limitations
13+
* under the License.
14+
*/
15+
16+
package userdetails
17+
18+
import (
19+
"encoding/json"
20+
"errors"
21+
"fmt"
22+
23+
"github.com/supertokens/supertokens-golang/ingredients/emaildelivery"
24+
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
25+
"github.com/supertokens/supertokens-golang/recipe/emailverification"
26+
"github.com/supertokens/supertokens-golang/supertokens"
27+
)
28+
29+
type userEmailVerifyTokenPost struct {
30+
Status string `json:"status"`
31+
}
32+
33+
type userEmailverifyTokenPostRequestBody struct {
34+
UserId *string `json:"userId"`
35+
}
36+
37+
func UserEmailVerifyTokenPost(apiInterface dashboardmodels.APIInterface, options dashboardmodels.APIOptions) (userEmailVerifyTokenPost, error) {
38+
body, err := supertokens.ReadFromRequest(options.Req)
39+
40+
if err != nil {
41+
return userEmailVerifyTokenPost{}, err
42+
}
43+
44+
var readBody userEmailverifyTokenPostRequestBody
45+
err = json.Unmarshal(body, &readBody)
46+
if err != nil {
47+
return userEmailVerifyTokenPost{}, err
48+
}
49+
50+
if readBody.UserId == nil {
51+
return userEmailVerifyTokenPost{}, supertokens.BadInputError{
52+
Msg: "Required parameter 'userId' is missing",
53+
}
54+
}
55+
56+
emailresponse, emailErr := emailverification.GetRecipeInstance().GetEmailForUserID(*readBody.UserId, supertokens.MakeDefaultUserContextFromAPI(options.Req))
57+
58+
if emailErr != nil {
59+
return userEmailVerifyTokenPost{}, emailErr
60+
}
61+
62+
if emailresponse.OK == nil {
63+
return userEmailVerifyTokenPost{}, errors.New("Should never come here")
64+
}
65+
66+
emailVerificationToken, tokenError := emailverification.CreateEmailVerificationToken(*readBody.UserId, &emailresponse.OK.Email)
67+
68+
if tokenError != nil {
69+
return userEmailVerifyTokenPost{}, tokenError
70+
}
71+
72+
if emailVerificationToken.EmailAlreadyVerifiedError != nil {
73+
return userEmailVerifyTokenPost{
74+
Status: "EMAIL_ALREADY_VERIFIED_ERROR",
75+
}, nil
76+
}
77+
78+
emailVerificationURL := fmt.Sprintf(
79+
"%s%s/verify-email?token=%s&rid=%s",
80+
options.AppInfo.WebsiteDomain.GetAsStringDangerous(),
81+
options.AppInfo.WebsiteBasePath.GetAsStringDangerous(),
82+
emailVerificationToken.OK.Token,
83+
options.RecipeID,
84+
)
85+
86+
emailverification.SendEmail(emaildelivery.EmailType{
87+
EmailVerification: &emaildelivery.EmailVerificationType{
88+
User: emaildelivery.User{
89+
ID: *readBody.UserId,
90+
Email: emailresponse.OK.Email,
91+
},
92+
EmailVerifyLink: emailVerificationURL,
93+
},
94+
})
95+
96+
return userEmailVerifyTokenPost{
97+
Status: "OK",
98+
}, nil
99+
}

0 commit comments

Comments
 (0)