Skip to content

Commit

Permalink
fix auth circular deps
Browse files Browse the repository at this point in the history
  • Loading branch information
revmischa committed Jul 2, 2024
1 parent 6861568 commit 25887ff
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion web/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { GET, POST } from '@/auth';
export { GET, POST } from '@/app/lib/auth/next'
2 changes: 1 addition & 1 deletion web/app/lib/actions/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use server'

import { signIn, signOut } from '@/auth'
import { signIn, signOut } from '@/app/lib/auth/next'
import { AuthError } from 'next-auth'

export async function authenticate(redirectTo?: string) {
Expand Down
2 changes: 1 addition & 1 deletion web/auth.config.ts → web/app/lib/auth/auth.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NextAuthConfig, Session } from 'next-auth'
import CognitoProvider from 'next-auth/providers/cognito'
import { COGNITO_CLIENT_ID, COGNITO_USER_POOL_ID, REGION } from './config'
import { COGNITO_CLIENT_ID, COGNITO_USER_POOL_ID, REGION } from '@/config'
import { refreshTokensIfNeeded } from './auth'

if (process.env.NEXTAUTH_URL && process.env.NEXTAUTH_URL.includes('set-me-in-.env')) {
Expand Down
12 changes: 2 additions & 10 deletions web/auth.ts → web/app/lib/auth/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import NextAuth, { Session } from 'next-auth'
import { authConfig } from './auth.config'
import { COGNITO_CLIENT_ID, COGNITO_DOMAIN_NAME } from '@/config'
import { Session } from 'next-auth'
import type { JWT } from 'next-auth/jwt'
import { COGNITO_CLIENT_ID, COGNITO_DOMAIN_NAME } from './config'

interface CognitoRefreshTokenResult {
access_token: string
Expand Down Expand Up @@ -51,10 +50,3 @@ export const refreshTokensIfNeeded = async (session: Session): Promise<Session>
refreshToken: refreshedTokens?.refresh_token ?? session.refreshToken, // Fall back to old refresh token
}
}

export const {
auth,
signIn,
signOut,
handlers: { GET, POST },
} = NextAuth({ ...authConfig })
9 changes: 9 additions & 0 deletions web/app/lib/auth/next.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import NextAuth from 'next-auth'
import { authConfig } from './auth.config'

export const {
auth,
signIn,
signOut,
handlers: { GET, POST },
} = NextAuth({ ...authConfig })
2 changes: 1 addition & 1 deletion web/app/lib/ui/Authentication/Authentication.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { auth } from '@/auth'
import { auth } from '@/app/lib/auth/next'
import { LoginButton } from './LoginButton'
import { LogoutButton } from './LogoutButton'

Expand Down
2 changes: 1 addition & 1 deletion web/app/lib/ui/WebHeader/WebHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { auth } from '@/auth'
import { auth } from '@/app/lib/auth/next'
import { Authentication } from '../Authentication/Authentication'
import { WebNavigation } from './WebNavigation'

Expand Down
2 changes: 1 addition & 1 deletion web/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import NextAuth from 'next-auth'
import { authConfig } from './auth.config'
import { authConfig } from './app/lib/auth/auth.config'

export default NextAuth(authConfig).auth

Expand Down

0 comments on commit 25887ff

Please sign in to comment.