@@ -3,6 +3,7 @@ import type { APIGatewayProxyEvent, Context } from 'aws-lambda'
3
3
import { DbAuthHandler } from '@redwoodjs/auth-dbauth-api'
4
4
import type { DbAuthHandlerOptions , UserType } from '@redwoodjs/auth-dbauth-api'
5
5
6
+ import { cookieName } from 'src/lib/auth'
6
7
import { db } from 'src/lib/db'
7
8
8
9
export const handler = async (
@@ -18,11 +19,20 @@ export const handler = async (
18
19
// https://example.com/reset-password?resetToken=${user.resetToken}
19
20
//
20
21
// Whatever is returned from this function will be returned from
21
- // the `forgotPassword()` function that is destructured from `useAuth()`
22
+ // the `forgotPassword()` function that is destructured from `useAuth()`.
22
23
// You could use this return value to, for example, show the email
23
24
// address in a toast message so the user will know it worked and where
24
25
// to look for the email.
25
- handler : ( user ) => {
26
+ //
27
+ // Note that this return value is sent to the client in *plain text*
28
+ // so don't include anything you wouldn't want prying eyes to see. The
29
+ // `user` here has been sanitized to only include the fields listed in
30
+ // `allowedUserFields` so it should be safe to return as-is.
31
+ handler : ( user , _resetToken ) => {
32
+ // TODO: Send user an email/message with a link to reset their password,
33
+ // including the `resetToken`. The URL should look something like:
34
+ // `http://localhost:8910/reset-password?resetToken=${resetToken}`
35
+
26
36
return user
27
37
} ,
28
38
@@ -115,12 +125,7 @@ export const handler = async (
115
125
//
116
126
// If this returns anything else, it will be returned by the
117
127
// `signUp()` function in the form of: `{ message: 'String here' }`.
118
- handler : ( {
119
- username,
120
- hashedPassword,
121
- salt,
122
- userAttributes
123
- } ) => {
128
+ handler : ( { username, hashedPassword, salt, userAttributes } ) => {
124
129
return db . user . create ( {
125
130
data : {
126
131
email : username ,
@@ -165,17 +170,26 @@ export const handler = async (
165
170
resetTokenExpiresAt : 'resetTokenExpiresAt' ,
166
171
} ,
167
172
173
+ // A list of fields on your user object that are safe to return to the
174
+ // client when invoking a handler that returns a user (like forgotPassword
175
+ // and signup). This list should be as small as possible to be sure not to
176
+ // leak any sensitive information to the client.
177
+ allowedUserFields : [ 'id' , 'email' ] ,
178
+
168
179
// Specifies attributes on the cookie that dbAuth sets in order to remember
169
180
// who is logged in. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies
170
181
cookie : {
171
- HttpOnly : true ,
172
- Path : '/' ,
173
- SameSite : 'Strict' ,
174
- Secure : process . env . NODE_ENV !== 'development' ,
175
-
176
- // If you need to allow other domains (besides the api side) access to
177
- // the dbAuth session cookie:
178
- // Domain: 'example.com',
182
+ attributes : {
183
+ HttpOnly : true ,
184
+ Path : '/' ,
185
+ SameSite : 'Strict' ,
186
+ Secure : process . env . NODE_ENV !== 'development' ,
187
+
188
+ // If you need to allow other domains (besides the api side) access to
189
+ // the dbAuth session cookie:
190
+ // Domain: 'example.com',
191
+ } ,
192
+ name : cookieName ,
179
193
} ,
180
194
181
195
forgotPassword : forgotPasswordOptions ,
0 commit comments