Skip to content

Commit 18494fa

Browse files
authored
Enable eagerAuth for immediate access token availability (#11)
* optimize template to use eagerAuth feature * update to authkit-nextjs v2.7.0
1 parent bc89abe commit 18494fa

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

components/ConvexClientProvider.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ export function ConvexClientProvider({ children }: { children: ReactNode }) {
1919
}
2020

2121
function useAuthFromAuthKit() {
22-
const { user, loading } = useAuth();
22+
const { user, loading: isLoading } = useAuth();
2323
const { accessToken, getAccessToken, refresh } = useAccessToken();
2424

25-
const hasIncompleteAuth = (!!user && !accessToken) || (!user && !!accessToken);
26-
const isLoading = loading || hasIncompleteAuth;
2725
const authenticated = !!user && !!accessToken;
2826

29-
// Create a stable fetchAccessToken function
3027
const fetchAccessToken = useCallback(
3128
async ({ forceRefreshToken }: { forceRefreshToken?: boolean } = {}): Promise<string | null> => {
3229
if (!user) {

middleware.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { authkitMiddleware } from '@workos-inc/authkit-nextjs';
22

33
export default authkitMiddleware({
4+
eagerAuth: true,
45
middlewareAuth: {
56
enabled: true,
67
unauthenticatedPaths: ['/', '/sign-in', '/sign-up'],

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
"format": "prettier --write ."
2323
},
2424
"dependencies": {
25-
"@workos-inc/authkit-nextjs": "^2.6.0",
26-
"convex": "^1.26.2",
25+
"@workos-inc/authkit-nextjs": "^2.7.0",
26+
"convex": "^1.27.0",
2727
"next": "15.4.3",
2828
"react": "^19.0.0",
2929
"react-dom": "^19.0.0"

0 commit comments

Comments
 (0)