Skip to content

Commit 4dcdf8f

Browse files
committed
fix: Fix eslint errors
1 parent 7d0ec8d commit 4dcdf8f

File tree

13 files changed

+47
-29
lines changed

13 files changed

+47
-29
lines changed

dev/src/app/(app)/_components/AuthOverview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { auth } from "@/auth";
2-
import { DataFromCollectionSlug } from "payload";
2+
import type { DataFromCollectionSlug } from "payload";
33
import { getPayloadUser } from "../../../../../src";
44
import { SignInButton } from "./SignInButton";
55
import { SignOutButtonAuthjs } from "./SignOutButtonAuthjs";

dev/src/app/(app)/_components/ExampleList.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const ExampleList = async () => {
1818
overrideAccess: false,
1919
user: payloadUser,
2020
});
21+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2122
} catch (error: any) {
2223
return <p>Failed to load examples: {error.message}</p>;
2324
}

dev/src/app/(app)/_components/SignOutButtonPayload.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ export function SignOutButtonPayload({
77
}) {
88
return (
99
<button
10-
onClick={() => {
11-
fetch(`/api/${userCollectionSlug}/logout`, {
10+
type="button"
11+
onClick={async () => {
12+
await fetch(`/api/${userCollectionSlug}/logout`, {
1213
method: "POST",
1314
headers: {
1415
"Content-Type": "application/json",

dev/src/app/(app)/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import "./globals.scss";
33

44
const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
55
return (
6-
<html>
6+
<html lang="en">
77
<body>
88
<main>{children}</main>
99
</body>

dev/src/app/(app)/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import AuthOverview from "./_components/AuthOverview";
22
import ExampleList from "./_components/ExampleList";
33

4-
const Page = async () => {
4+
const Page = () => {
55
return (
66
<article className="container">
77
<AuthOverview />

dev/src/auth.config.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import jwt from "jsonwebtoken";
2-
import { NextAuthConfig, Profile } from "next-auth";
3-
import { JWT } from "next-auth/jwt";
2+
import type { NextAuthConfig, Profile } from "next-auth";
3+
import type { JWT } from "next-auth/jwt";
44
import github from "next-auth/providers/github";
55
import keycloak from "next-auth/providers/keycloak";
66

@@ -14,6 +14,7 @@ declare module "next-auth" {
1414
interface Profile {
1515
roles?: string[];
1616
}
17+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
1718
interface User extends Pick<JWT, "id" | "roles"> {}
1819
}
1920

@@ -38,7 +39,7 @@ export const authConfig: NextAuthConfig = {
3839
profile(profile, tokens) {
3940
// Add roles to the profile
4041
if (tokens.access_token) {
41-
let decodedToken = jwt.decode(tokens.access_token);
42+
const decodedToken = jwt.decode(tokens.access_token);
4243
if (decodedToken && typeof decodedToken !== "string") {
4344
profile.roles = decodedToken.resource_access?.[process.env.AUTH_KEYCLOAK_ID!]?.roles; // Extend the profile
4445
}
@@ -57,7 +58,7 @@ export const authConfig: NextAuthConfig = {
5758
strategy: "jwt",
5859
}, */
5960
callbacks: {
60-
jwt: async ({ token, user, profile }) => {
61+
jwt: ({ token, user, profile }) => {
6162
// Include user id in the JWT token
6263
if (user) {
6364
token.id = user.id;
@@ -68,7 +69,7 @@ export const authConfig: NextAuthConfig = {
6869
}
6970
return token;
7071
},
71-
session: async ({ session, user, token }) => {
72+
session: ({ session, user, token }) => {
7273
// session strategy: "jwt"
7374
if (token) {
7475
if (token.id) {
@@ -86,7 +87,7 @@ export const authConfig: NextAuthConfig = {
8687
console.log("signIn auth.ts");
8788
return true;
8889
}, */
89-
authorized: async ({ auth }) => {
90+
authorized: ({ auth }) => {
9091
// Logged in users are authenticated, otherwise redirect to login page
9192
return !!auth;
9293
},

src/authjs/PayloadAdapter.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// eslint-disable-next-line import/no-unresolved
21
import { getPayloadHMR } from "@payloadcms/next/utilities";
32
import type {
43
Adapter,
@@ -39,7 +38,6 @@ export function PayloadAdapter({
3938
}: PayloadAdapterOptions): Adapter {
4039
// Get the Payload instance
4140
if (!payload && payloadConfig) {
42-
// eslint-disable-next-line no-param-reassign
4341
payload = getPayloadHMR({ config: payloadConfig });
4442
}
4543
if (!payload) {
@@ -142,8 +140,9 @@ export function PayloadAdapter({
142140
collection: userCollectionSlug,
143141
id: account.userId,
144142
})) as User | undefined;
145-
if (!payloadUser)
143+
if (!payloadUser) {
146144
throw new Error(`Failed to link account: User '${account.userId}' not found`);
145+
}
147146

148147
payloadUser = (await (
149148
await payload
@@ -175,10 +174,11 @@ export function PayloadAdapter({
175174
},
176175
})
177176
).docs.at(0) as User | undefined;
178-
if (!payloadUser)
177+
if (!payloadUser) {
179178
throw new Error(
180179
`Failed to unlink account: User from provider '${provider}' with account ID '${providerAccountId}' not found`,
181180
);
181+
}
182182

183183
payloadUser = (await (
184184
await payload
@@ -204,8 +204,9 @@ export function PayloadAdapter({
204204
collection: userCollectionSlug,
205205
id: session.userId,
206206
})) as User | undefined;
207-
if (!payloadUser)
207+
if (!payloadUser) {
208208
throw new Error(`Failed to create session: User '${session.userId}' not found`);
209+
}
209210

210211
payloadUser = (await (
211212
await payload
@@ -234,10 +235,14 @@ export function PayloadAdapter({
234235
},
235236
})
236237
).docs.at(0) as User | undefined;
237-
if (!payloadUser) return null;
238+
if (!payloadUser) {
239+
return null;
240+
}
238241

239242
const session = payloadUser.sessions?.find(s => s.sessionToken === sessionToken);
240-
if (!session) return null;
243+
if (!session) {
244+
return null;
245+
}
241246

242247
return {
243248
user: toAdapterUser(payloadUser),
@@ -259,8 +264,9 @@ export function PayloadAdapter({
259264
},
260265
})
261266
).docs.at(0) as User | undefined;
262-
if (!payloadUser)
267+
if (!payloadUser) {
263268
throw new Error(`Failed to update session: Session '${session.sessionToken}' not found`);
269+
}
264270

265271
payloadUser = (await (
266272
await payload
@@ -294,8 +300,9 @@ export function PayloadAdapter({
294300
},
295301
})
296302
).docs.at(0) as User | undefined;
297-
if (!payloadUser)
303+
if (!payloadUser) {
298304
throw new Error(`Failed to delete session: Session '${sessionToken}' not found`);
305+
}
299306

300307
payloadUser = (await (
301308
await payload
@@ -371,7 +378,9 @@ export function PayloadAdapter({
371378
},
372379
})
373380
).docs.at(0) as User | undefined;
374-
if (!payloadUser) return null;
381+
if (!payloadUser) {
382+
return null;
383+
}
375384

376385
const verificationToken = payloadUser.verificationTokens?.find(t => t.token === token);
377386

src/authjs/withPayload.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-param-reassign */
21
import type { NextAuthConfig } from "next-auth";
32
import { PayloadAdapter, type PayloadAdapterOptions } from "./PayloadAdapter";
43

@@ -43,7 +42,7 @@ export function withPayload(
4342
*/
4443
if (updateUserOnSignIn === true) {
4544
const { signIn, ...callbacks } = authjsConfig.callbacks ?? {};
46-
// eslint-disable-next-line no-inner-declarations
45+
4746
async function updateUserOnSignInWrapper(
4847
params: Parameters<NonNullable<typeof signIn>>[0],
4948
): Promise<boolean> {

src/payload/AuthjsAuthStrategy.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export function AuthjsAuthStrategy(
2424
const session = await auth();
2525

2626
// If no session, return null user
27-
if (!session?.user) return { user: null };
27+
if (!session?.user) {
28+
return { user: null };
29+
}
2830

2931
// Find user in database
3032
const payloadUser = (
@@ -41,7 +43,9 @@ export function AuthjsAuthStrategy(
4143
},
4244
})
4345
).docs.at(0);
44-
if (!payloadUser) return { user: null };
46+
if (!payloadUser) {
47+
return { user: null };
48+
}
4549

4650
// Return user to payload cms
4751
return {

src/payload/generateUsersCollection.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ function createOrPatchField(fields: Field[], field: Field): void {
162162
} else {
163163
if ("fields" in field && "fields" in existingField) {
164164
field.fields.forEach(subField => createOrPatchField(existingField.fields, subField));
165-
// eslint-disable-next-line no-param-reassign
166165
field.fields = existingField.fields;
167166
}
168167
Object.assign(existingField, field);

0 commit comments

Comments
 (0)