Skip to content

Commit 4a115c5

Browse files
committed
Update readme
1 parent af4e967 commit 4a115c5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

api/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,31 @@ Then, we switched the original return statement to a switch statement. This is d
121121
- If the URL path is `/auth/oauth`, it will execute `oAuthHandler.invoke()`. This is new behavior introduced to handle OAuth requests.
122122
In other words, the switch statement allows the application to handle both traditional and OAuth authentication requests, routing them to the appropriate handler based on the URL path.
123123

124+
### Updating the api `auth` library
125+
Double check that your `getCurrentUser` method is selecting the user's `email` attribute, if it exists on your `user` model. For example, if you're using a field called `username` as your username, you might need to make a change that looks like this:
126+
```diff
127+
export const getCurrentUser = async (
128+
session: Decoded
129+
): Promise<ICurrentUser> => {
130+
if (!session || typeof session.id !== 'string') {
131+
throw new Error('Invalid session')
132+
}
133+
134+
const user = await db.user.findUnique({
135+
where: { id: session.id },
136+
select: {
137+
id: true,
138+
username: true,
139+
+ email: true
140+
},
141+
})
142+
if (!user) throw new AuthenticationError('You are not logged in.')
143+
else return user
144+
}
145+
```
146+
147+
This is optional, but helpful as another way to associate linked accounts with your users.
148+
124149
### All done!
125150
And that's it! If you haven't yet set up the `web` side, go check out [those instructions](https://github.com/spoonjoy/redwoodjs-dbauth-oauth/blob/main/web/README.md#web-package-for-redwoodjs-dbauth-oauth-plugin).
126151

0 commit comments

Comments
 (0)