-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc5fa8a
commit ca5309b
Showing
17 changed files
with
173 additions
and
308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,11 @@ | |
"packageManager": "[email protected]", | ||
"engines": { | ||
"node": "^20" | ||
}, | ||
"pnpm": { | ||
"overrides": { | ||
"@trpc/client": "11.0.0-rc.482", | ||
"@trpc/server": "11.0.0-rc.482" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export interface Credentials { | ||
accessToken: string; | ||
refreshToken: string; | ||
expireAt: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/figma-plugin/src/ui/modules/providers/api-provider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useMemo } from 'react'; | ||
import { TRPCReactProvider } from '@ds-project/api/react'; | ||
import { useAuth } from './auth-provider'; | ||
import { tokenRefreshLink } from 'trpc-token-refresh-link'; | ||
import type { AppRouter } from '../../../../../api/src/app-router'; | ||
|
||
export function ApiProvider({ children }: { children: React.ReactNode }) { | ||
const { credentials, refreshAccessToken, logout } = useAuth(); | ||
|
||
const authTrpcLink = useMemo( | ||
() => | ||
tokenRefreshLink<AppRouter>({ | ||
tokenRefreshNeeded: () => { | ||
if (!credentials) { | ||
return false; | ||
} | ||
|
||
return credentials.expireAt - Date.now() < 0; | ||
}, | ||
fetchAccessToken: async () => { | ||
console.log('✨ Refreshing token...'); | ||
try { | ||
void refreshAccessToken(); | ||
} catch (error) { | ||
await logout(); | ||
} | ||
}, | ||
}), | ||
[credentials, logout, refreshAccessToken] | ||
); | ||
|
||
return ( | ||
<TRPCReactProvider | ||
accessToken={credentials?.accessToken} | ||
source="figma" | ||
trpcLinks={[authTrpcLink]} | ||
> | ||
{children} | ||
</TRPCReactProvider> | ||
); | ||
} |
Oops, something went wrong.