|
1 | 1 | import NextAuth from 'next-auth'; |
| 2 | +import type { Session } from 'next-auth'; |
| 3 | +import type { JWT } from 'next-auth/jwt'; |
| 4 | +import type { User as NextAuthUser } from 'next-auth'; |
2 | 5 | import Credentials from 'next-auth/providers/credentials'; |
3 | 6 | import { login, getMe as getMeBase } from '@/lib/api/auth'; |
4 | 7 | import Google from 'next-auth/providers/google'; |
@@ -89,7 +92,11 @@ export const authConfig = { |
89 | 92 | password: { label: 'Password', type: 'password' }, |
90 | 93 | accessToken: { label: 'Access Token', type: 'text' }, |
91 | 94 | }, |
92 | | - authorize: async (credentials: any) => { |
| 95 | + authorize: async ( |
| 96 | + credentials: |
| 97 | + | Partial<Record<'email' | 'password' | 'accessToken', unknown>> |
| 98 | + | undefined |
| 99 | + ) => { |
93 | 100 | if ( |
94 | 101 | typeof credentials?.accessToken === 'string' && |
95 | 102 | !credentials?.email && |
@@ -152,21 +159,28 @@ export const authConfig = { |
152 | 159 | }), |
153 | 160 | ], |
154 | 161 | callbacks: { |
155 | | - authorized: async ({ auth }: { auth: any }) => { |
| 162 | + authorized: async ({ auth }: { auth: Session | null }) => { |
156 | 163 | // Logged in users are authenticated, otherwise redirect to login page |
157 | 164 | return !!auth; |
158 | 165 | }, |
159 | | - async jwt({ token, user }: any) { |
| 166 | + async jwt({ token, user }: { token: JWT; user?: NextAuthUser | null }) { |
160 | 167 | if (user) { |
161 | | - const u = user as { accessToken?: string; refreshToken?: string }; |
| 168 | + const u = user as NextAuthUser & { |
| 169 | + accessToken?: string; |
| 170 | + refreshToken?: string; |
| 171 | + }; |
162 | 172 | token.accessToken = u.accessToken; |
163 | 173 | token.refreshToken = u.refreshToken; |
164 | 174 | } |
165 | 175 | return token; |
166 | 176 | }, |
167 | | - async session({ session, token }: any) { |
168 | | - session.user.accessToken = token.accessToken as string | undefined; |
169 | | - session.user.refreshToken = token.refreshToken as string | undefined; |
| 177 | + async session({ session, token }: { session: Session; token: JWT }) { |
| 178 | + session.user.accessToken = ( |
| 179 | + token as JWT & { accessToken?: string } |
| 180 | + ).accessToken; |
| 181 | + session.user.refreshToken = ( |
| 182 | + token as JWT & { refreshToken?: string } |
| 183 | + ).refreshToken; |
170 | 184 | return session; |
171 | 185 | }, |
172 | 186 | }, |
|
0 commit comments