Skip to content

Commit

Permalink
dbAuth: Catch fetch failure in getToken (#9119)
Browse files Browse the repository at this point in the history
We have this comment in `useToken()`


https://github.com/redwoodjs/redwood/blob/4b734d30c6830172194a2518ae0c2cbf6f1a0904/packages/auth/src/AuthProvider/useToken.ts#L7-L14

And for example our Netlify auth implementation does this:


https://github.com/redwoodjs/redwood/blob/4b734d30c6830172194a2518ae0c2cbf6f1a0904/packages/auth-providers/netlify/web/src/netlify.ts#L68-L78

But dbAuth let the exception slip through to `useToken`.
This PR adds a `catch` to the promise and returns `null`, just like
Netlify (and others)


Before merging this though, I need to make sure I'm not undoing the fix
@standup75 did in #8284
(@standup75 can you say off the top of your head if my code will work or
not?)
  • Loading branch information
Tobbe authored and jtoar committed Sep 6, 2023
1 parent df53f95 commit 27f0e90
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/auth-providers/dbAuth/web/src/dbAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ export function createDbAuthClient({
cachedToken = tokenText.length === 0 ? null : tokenText
return cachedToken
})
.catch(() => {
return null
})
.finally(() => {
getTokenPromise = null
})
Expand Down

0 comments on commit 27f0e90

Please sign in to comment.