Skip to content

Commit b881764

Browse files
committed
Upgrade deps
1 parent 8b02797 commit b881764

File tree

9 files changed

+1012
-872
lines changed

9 files changed

+1012
-872
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import NextAuth, { AuthOptions, Session } from "next-auth";
2+
import GoogleProvider from "next-auth/providers/google";
3+
import { prismaClient } from "db";
4+
import CredentialsProvider from "next-auth/providers/credentials";
5+
6+
export const authOptions: AuthOptions = {
7+
debug: false,
8+
secret: process.env.NEXTAUTH_SECRET,
9+
providers: [
10+
GoogleProvider({
11+
clientId: process.env.GOOGLE_CLIENT_ID!,
12+
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
13+
}),
14+
CredentialsProvider({
15+
name: "Credentials",
16+
credentials: {
17+
username: { label: "Username", type: "text", placeholder: "demo" },
18+
password: {
19+
label: "Password",
20+
type: "password",
21+
placeholder: "demo",
22+
},
23+
},
24+
async authorize(credentials, req) {
25+
const user = {
26+
id: "userid1",
27+
name: "Demo name",
28+
29+
};
30+
31+
if (user) {
32+
return user;
33+
}
34+
return null;
35+
},
36+
}),
37+
],
38+
callbacks: {
39+
signIn: async ({ user, account, profile }) => {
40+
//security
41+
if (user.email === "[email protected]") {
42+
return true;
43+
}
44+
45+
//restrict domain
46+
if (
47+
process.env.RESTRICT_EMAIL_DOMAIN &&
48+
!profile?.email?.endsWith(`@${process.env.RESTRICT_EMAIL_DOMAIN}`)
49+
) {
50+
return false;
51+
}
52+
53+
//ok
54+
return true;
55+
},
56+
jwt: async ({ token, user, trigger, account }) => {
57+
// console.log("jwt", { token, user, trigger, account, session });
58+
59+
if (trigger === "signIn" && account?.provider === "google") {
60+
if (!user.email) {
61+
throw new Error("No email returned from google");
62+
}
63+
// No need for prisma adapter with custom query and jwt strategy
64+
const adminUser = await prismaClient.adminUser.upsert({
65+
select: {
66+
id: true,
67+
email: true,
68+
role: true,
69+
name: true,
70+
image: true,
71+
},
72+
where: { email: user.email },
73+
update: {
74+
// TODO: last login at
75+
},
76+
create: {
77+
name: user.name,
78+
email: user.email,
79+
image: user.image,
80+
role: "OWNER",
81+
},
82+
});
83+
84+
// even if you don't return token fields, they will be added to the jwt token
85+
// such as iat, exp, jti etc
86+
87+
return <Session["user"]>{
88+
image: adminUser.image,
89+
name: adminUser.name,
90+
userId: adminUser.id,
91+
email: adminUser.email,
92+
role: adminUser.role,
93+
};
94+
}
95+
96+
return token;
97+
},
98+
session: async ({ session, token }) => {
99+
// console.log("session", { session, user, token, newSession, trigger });
100+
101+
const { image, name, userId, email, role } = token as Session["user"]; // cast to Session["user"] next auth doesn't know...
102+
103+
session.user = { image, name, userId, email, role }; // add to session only the good fields, the rest is token, not needed
104+
105+
return session;
106+
},
107+
},
108+
};

apps/admin/app/api/auth/[...nextauth]/route.ts

+2-105
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,5 @@
1-
import NextAuth, { AuthOptions, Session } from "next-auth";
2-
import GoogleProvider from "next-auth/providers/google";
3-
import { prismaClient } from "db";
4-
import CredentialsProvider from "next-auth/providers/credentials";
5-
6-
export const authOptions: AuthOptions = {
7-
debug: false,
8-
secret: process.env.NEXTAUTH_SECRET,
9-
providers: [
10-
GoogleProvider({
11-
clientId: process.env.GOOGLE_CLIENT_ID!,
12-
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
13-
}),
14-
CredentialsProvider({
15-
name: "Credentials",
16-
credentials: {
17-
username: { label: "Username", type: "text", placeholder: "demo" },
18-
password: {
19-
label: "Password",
20-
type: "password",
21-
placeholder: "demo",
22-
},
23-
},
24-
async authorize(credentials, req) {
25-
const user = {
26-
id: "userid1",
27-
name: "Demo name",
28-
29-
};
30-
31-
if (user) {
32-
return user;
33-
}
34-
return null;
35-
},
36-
}),
37-
],
38-
callbacks: {
39-
signIn: async ({ user, account, profile }) => {
40-
//security
41-
if (user.email === "[email protected]") {
42-
return true;
43-
}
44-
45-
//restrict domain
46-
if (
47-
process.env.RESTRICT_EMAIL_DOMAIN &&
48-
!profile?.email?.endsWith(`@${process.env.RESTRICT_EMAIL_DOMAIN}`)
49-
) {
50-
return false;
51-
}
52-
53-
//ok
54-
return true;
55-
},
56-
jwt: async ({ token, user, trigger, account }) => {
57-
// console.log("jwt", { token, user, trigger, account, session });
58-
59-
if (trigger === "signIn" && account?.provider === "google") {
60-
// No need for prisma adapter with custom query and jwt strategy
61-
const adminUser = await prismaClient.adminUser.upsert({
62-
select: {
63-
id: true,
64-
email: true,
65-
role: true,
66-
name: true,
67-
image: true,
68-
},
69-
where: { email: user.email },
70-
update: {
71-
// TODO: last login at
72-
},
73-
create: {
74-
name: user.name,
75-
email: user.email,
76-
image: user.image,
77-
role: "OWNER",
78-
},
79-
});
80-
81-
// even if you don't return token fields, they will be added to the jwt token
82-
// such as iat, exp, jti etc
83-
84-
return <Session["user"]>{
85-
image: adminUser.image,
86-
name: adminUser.name,
87-
userId: adminUser.id,
88-
email: adminUser.email,
89-
role: adminUser.role,
90-
};
91-
}
92-
93-
return token;
94-
},
95-
session: async ({ session, token }) => {
96-
// console.log("session", { session, user, token, newSession, trigger });
97-
98-
const { image, name, userId, email, role } = token as Session["user"]; // cast to Session["user"] next auth doesn't know...
99-
100-
session.user = { image, name, userId, email, role }; // add to session only the good fields, the rest is token, not needed
101-
102-
return session;
103-
},
104-
},
105-
};
1+
import NextAuth from "next-auth";
2+
import { authOptions } from "./authOptions";
1063

1074
const nextAuth = NextAuth(authOptions);
1085

apps/admin/app/page.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ import { SessionProvider } from "next-auth/react";
33
import ReactAdmin from "./ReactAdmin";
44

55
const HomePage = () => {
6-
return (
7-
<SessionProvider>
8-
<ReactAdmin />
9-
</SessionProvider>
10-
);
6+
return null;
117
};
128

139
export default HomePage;

apps/admin/auth/checkAccess.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getServerSession } from "next-auth";
2-
import { authOptions } from "../app/api/auth/[...nextauth]/route";
2+
import { authOptions } from "../app/api/auth/[...nextauth]/authOptions";
33
import {
44
RaPayload,
55
ReactAdminFetchActions,

apps/admin/package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@
1111
},
1212
"dependencies": {
1313
"@babel/core": "7.23.7",
14-
"@mui/icons-material": "^5.15.11",
15-
"@mui/material": "^5.15.11",
16-
"@mui/styles": "^5.15.11",
17-
"axios": "^1.6.7",
14+
"@mui/icons-material": "^5.15.14",
15+
"@mui/material": "^5.15.14",
16+
"@mui/styles": "^5.15.14",
17+
"axios": "^1.6.8",
1818
"db": "workspace:*",
1919
"lodash": "^4.17.21",
2020
"next": "14.0.4",
21-
"next-auth": "^4.24.6",
21+
"next-auth": "^4.24.7",
2222
"next-auth-prisma-adapter": "workspace:*",
2323
"ra-data-simple-prisma": "workspace:*",
2424
"react": "18.2.0",
25-
"react-admin": "^4.16.11",
25+
"react-admin": "^4.16.13",
2626
"react-admin-json-view": "^2.0.0",
2727
"react-dom": "18.2.0"
2828
},
2929
"devDependencies": {
30-
"@types/lodash": "^4.14.202",
30+
"@types/lodash": "^4.17.0",
3131
"@types/node": "20.10.6",
3232
"@types/react": "18.2.46",
3333
"@types/react-dom": "18.2.18",

packages/ra-data-simple-prisma/package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,16 @@
3838
"@prisma/client": ">=3"
3939
},
4040
"dependencies": {
41-
"axios": "^1.5.0",
41+
"axios": "^1.6.8",
4242
"deepmerge": "^4.3.1",
43-
"deverything": "^0.28.1",
44-
"set-value": "^4.1.0"
43+
"deverything": "^0.48.0"
4544
},
4645
"devDependencies": {
47-
"@types/node": "^20.7.0",
46+
"@types/node": "^20.11.30",
4847
"eslint-config-custom": "workspace:*",
4948
"jest": "^29.7.0",
50-
"react-admin": "^4.14.3",
49+
"react-admin": "^4.16.13",
5150
"tsup": "^7.2.0",
52-
"typescript": "^5.2.2"
51+
"typescript": "^5.4.3"
5352
}
5453
}

packages/ra-data-simple-prisma/src/extractOrderBy.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GetListRequest, GetManyReferenceRequest } from "./Http";
2-
import setObjectProp from "set-value";
2+
import { setObjectPath } from "deverything";
33

44
export const extractOrderBy = (
55
req: GetListRequest | GetManyReferenceRequest
@@ -12,7 +12,7 @@ export const extractOrderBy = (
1212
const { field, order } = sort;
1313
// TODO: use isField() or you will sort underscore fields
1414
if (field && order) {
15-
setObjectProp(orderBy, field, order.toLowerCase());
15+
setObjectPath(orderBy, field, order.toLowerCase());
1616
}
1717
}
1818

packages/ra-data-simple-prisma/src/extractWhere.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { PlainObject, isObject } from "deverything";
1+
import { PlainObject, isObject, setObjectPath } from "deverything";
22
import { GetListRequest, GetManyReferenceRequest } from "./Http";
33
import { isNotField } from "./lib/isNotField";
4-
import setObjectProp from "set-value";
54

65
const prismaOperators = [
76
"contains",
@@ -42,7 +41,7 @@ export const extractWhere = (
4241
const hasOperator = prismaOperators.some((operator) => {
4342
if (colName.endsWith(`_${operator}`)) {
4443
[colName] = colName.split(`_${operator}`);
45-
setObjectProp(where, colName, { [operator]: value }, { merge: true });
44+
setObjectPath(where, colName, { [operator]: value });
4645
return true;
4746
}
4847
});
@@ -55,9 +54,10 @@ export const extractWhere = (
5554
colName.endsWith(`_eq`)
5655
) {
5756
const [cleanColName] = colName.split(/(_enum|_exact|_eq)$/);
58-
setObjectProp(where, cleanColName, value);
57+
setObjectPath(where, cleanColName, value);
5958
} else if (colName === "q") {
60-
// i.e. full-text search, not sure why this has come as a column name?
59+
// i.e. when filterToQuery is not set on AutoCompleteInput, but we don't know all the fields to search against
60+
console.info("Filter not handled:", colName, value);
6161
} else if (
6262
colName === "id" ||
6363
colName === "uuid" ||
@@ -68,11 +68,11 @@ export const extractWhere = (
6868
typeof value === "boolean" ||
6969
value === null // if the client sends null, than that is also a valid (exact) filter!
7070
) {
71-
setObjectProp(where, colName, value);
71+
setObjectPath(where, colName, value);
7272
} else if (Array.isArray(value)) {
73-
setObjectProp(where, colName, { in: value });
73+
setObjectPath(where, colName, { in: value });
7474
} else if (typeof value === "string") {
75-
setObjectProp(where, colName, {
75+
setObjectPath(where, colName, {
7676
contains: value,
7777
mode: options?.filterMode,
7878
});
@@ -81,7 +81,7 @@ export const extractWhere = (
8181
// https://www.prisma.io/docs/concepts/components/prisma-client/working-with-fields/working-with-json-fields#filter-on-object-property
8282
const { path, equals } = formatPrismaPostgresNestedJsonFilter(value);
8383
if (path.length && equals) {
84-
setObjectProp(where, colName, { path, equals });
84+
setObjectPath(where, colName, { path, equals });
8585
}
8686
} else {
8787
console.info("Filter not handled:", colName, value);

0 commit comments

Comments
 (0)