Skip to content

Commit d5c2027

Browse files
authored
v2.16.5 (#233)
2 parents 1b1051e + 5d3ba1d commit d5c2027

8 files changed

Lines changed: 75 additions & 34 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import NextAuth from "next-auth";
22
import axios from "axios";
33
import GoogleProvider from "next-auth/providers/google";
4+
import { profile } from "console";
5+
import Swal from "sweetalert2";
46

57
const emoji: { [key: string]: string } = {
68
developer: "<:developer:1222933983164235876>",
@@ -17,7 +19,9 @@ const handler = NextAuth({
1719
}),
1820
],
1921
callbacks: {
20-
async signIn({ account }) {
22+
async signIn({ account, profile }) {
23+
if (!profile?.email?.endsWith("@ms.mingdao.edu.tw"))
24+
return "/?error=not_md";
2125
if (account) {
2226
const urlencoded = new URLSearchParams();
2327
urlencoded.append("googleToken", String(account.access_token));
@@ -62,6 +66,7 @@ const handler = NextAuth({
6266
});
6367
}
6468
}
69+
6570
return true;
6671
},
6772
async jwt({ token, account }) {

app/api/webhook/login/route.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import axios from "axios";
22
import { NextRequest, NextResponse } from "next/server";
33

4+
function isDev(req: NextRequest) {
5+
const urlObj = new URL(req.url);
6+
7+
return urlObj.hostname !== "sig.mingdao.edu.tw";
8+
}
9+
410
export async function POST(req: NextRequest) {
511
const data = await req.formData();
612
const content = {
713
username: "MDSIG Login",
8-
avatar_url:
9-
"https://sig.mingdao.edu.tw/images/sig2pfp.png",
14+
avatar_url: "https://sig.mingdao.edu.tw/images/sig2pfp.png",
1015
embeds: [
1116
{
12-
title: `${data.get("name")} ${req.url.includes("localhost") ? "(Development)" : ""}${req.url.includes("dev") ? "(Development)" : ""}`,
17+
title: `${data.get("name")} ${isDev(req) ? "(Development)" : ""}`,
1318
description: data.get("description"),
1419
color: parseInt("0x34e718"),
1520
thumbnail: {
@@ -65,8 +70,7 @@ export async function POST(req: NextRequest) {
6570
timestamp: new Date().toISOString(),
6671
footer: {
6772
text: "MDSIG 2.0 Login System",
68-
icon_url:
69-
"https://sig.mingdao.edu.tw/images/sig2pfp.png",
73+
icon_url: "https://sig.mingdao.edu.tw/images/sig2pfp.png",
7074
},
7175
},
7276
],

app/page.tsx

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,43 @@ import Information from "./(home)/desktop/Information";
99
import ThreadsListMobile from "./(home)/mobile/ThreadsList";
1010
import useIsMobile from "@/utils/useIsMobile";
1111

12-
const Home = () => {
12+
// Module
13+
import Swal from "sweetalert2";
14+
import { useSearchParams, useRouter } from "next/navigation";
15+
import { useEffect } from "react";
16+
17+
export default function Home() {
1318
const isMobile = useIsMobile();
19+
const router = useRouter();
20+
const searchParams = useSearchParams();
21+
const error = searchParams.get("error");
22+
23+
useEffect(() => {
24+
if (error === "not_md") {
25+
Swal.fire({
26+
title: "Login Fail",
27+
text: "You should use your Mingdao email to login!",
28+
icon: "error",
29+
confirmButtonText: "Sure",
30+
allowEscapeKey: false,
31+
allowOutsideClick: false,
32+
customClass: {
33+
container: "select-none",
34+
},
35+
focusConfirm: false,
36+
background: "#fff url(/images/trees.png)",
37+
backdrop: `
38+
rgba(0,0,123,0.4)
39+
url("/images/nyan-cat.gif")
40+
left top
41+
no-repeat
42+
`,
43+
preConfirm: () => {
44+
router.push("/");
45+
}
46+
});
47+
}
48+
}, [error, router]);
1449

1550
if (isMobile) {
1651
return <ThreadsListMobile />;
@@ -22,6 +57,4 @@ const Home = () => {
2257
</SplitBlock>
2358
);
2459
}
25-
};
26-
27-
export default Home;
60+
}

app/ping/route.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,38 @@ import axios from "axios";
55
import ReadableTime from "@/modules/api/ReadableTime";
66
import GetOnlineAppVersion from "@/modules/api/GetOnlineAppVersion";
77

8-
98
export async function GET() {
109
const packageJSON = JSON.parse(readFileSync("./package.json").toString());
1110
const { mainVersion, developmentVersion } = await GetOnlineAppVersion();
1211

13-
const apiResponse = await axios.get(`${process.env.NEXT_PUBLIC_API_URL}/ping`);
12+
const apiResponse = await axios.get(
13+
`${process.env.NEXT_PUBLIC_API_URL}/ping`,
14+
);
1415
const apiData = apiResponse.data;
1516

1617
const data: any = {
17-
"Frontend": {
18-
"status": "Online",
19-
"uptime": ReadableTime(Math.round(performance.now()))["string"],
20-
"currentVersion": packageJSON.version,
21-
"latestVersion": {
22-
"main": mainVersion,
23-
"development": developmentVersion
18+
Frontend: {
19+
status: "Online",
20+
uptime: ReadableTime(Math.round(performance.now()))["string"],
21+
currentVersion: packageJSON.version,
22+
latestVersion: {
23+
main: mainVersion,
24+
development: developmentVersion,
2425
},
25-
"upToDate": {
26-
"main": mainVersion <= packageJSON.version,
27-
"development": developmentVersion <= packageJSON.version
26+
upToDate: {
27+
main: mainVersion >= packageJSON.version,
28+
development: developmentVersion >= packageJSON.version,
2829
},
29-
},
30-
"Backend": {
31-
"status": apiData.service.replace("up", "Online") || "Offline",
32-
"uptime": apiData.uptime || "N/A",
33-
"currentVersion": apiData.version.current || "N/A",
34-
"latestVersion": apiData.version.latest || "N/A",
35-
"upToDate": apiData.version.upToDate || "N/A"
36-
}
30+
},
31+
Backend: {
32+
status: apiData.service.replace("up", "Online") || "Offline",
33+
uptime: apiData.uptime || "N/A",
34+
currentVersion: apiData.version.current || "N/A",
35+
latestVersion: apiData.version.latest || "N/A",
36+
upToDate: apiData.version.upToDate || "N/A",
37+
},
3738
};
3839

39-
4040
return NextResponse.json(data);
4141
}
4242

@@ -45,4 +45,4 @@ export const dynamicParams = false;
4545
export const revalidate = false;
4646
export const fetchCache = "auto";
4747
export const runtime = "nodejs";
48-
export const preferredRegion = "auto";
48+
export const preferredRegion = "auto";

next.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/** @type {import('next').NextConfig} */
22
const path = require("path");
33
const nextConfig = {
4-
swcMinify: false,
54
experimental: {
65
missingSuspenseWithCSRBailout: false,
76
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mdsig-frontend",
3-
"version": "2.16.4",
3+
"version": "2.16.5",
44
"private": true,
55
"scripts": {
66
"dev": "next dev",

public/images/nyan-cat.gif

59.5 KB
Loading

public/images/trees.png

41.4 KB
Loading

0 commit comments

Comments
 (0)