-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #476 from s-hirano-ist/fix--500-error-on-generate-…
…static-params fix: 500 error on generate static params
- Loading branch information
Showing
11 changed files
with
149 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,9 @@ | ||
"use client"; | ||
import { Button } from "@/components/ui/button"; | ||
import { changeContentsStatus } from "@/features/update-status/actions/change-contents-status"; | ||
import { changeNewsStatus } from "@/features/update-status/actions/change-news-status"; | ||
import { useToast } from "@/hooks/use-toast"; | ||
import { useState } from "react"; | ||
import { Unauthorized } from "@/components/unauthorized"; | ||
import { checkAdminPermission } from "@/features/auth/utils/role"; | ||
import { ChangeStatusButtons } from "@/features/dump/components/change-status-buttons"; | ||
|
||
export default function Page() { | ||
const { toast } = useToast(); | ||
export default async function Page() { | ||
const hasAdminPermission = await checkAdminPermission(); | ||
|
||
const [buttonDisabled, setButtonDisabled] = useState(false); | ||
|
||
const handleNewsUpdateStatus = async () => { | ||
setButtonDisabled(true); | ||
const response = await changeNewsStatus("UPDATE"); | ||
// TODO: revalidate path | ||
toast({ | ||
variant: response.success ? "default" : "destructive", | ||
description: response.message, | ||
}); | ||
setButtonDisabled(false); | ||
}; | ||
|
||
const handleNewsRevertStatus = async () => { | ||
setButtonDisabled(true); | ||
const response = await changeNewsStatus("REVERT"); | ||
// TODO: revalidate path | ||
toast({ | ||
variant: response.success ? "default" : "destructive", | ||
description: response.message, | ||
}); | ||
setButtonDisabled(false); | ||
}; | ||
|
||
const handleContentsUpdateStatus = async () => { | ||
setButtonDisabled(true); | ||
const response = await changeContentsStatus("UPDATE"); | ||
// TODO: revalidate path | ||
toast({ | ||
variant: response.success ? "default" : "destructive", | ||
description: response.message, | ||
}); | ||
setButtonDisabled(false); | ||
}; | ||
|
||
const handleContentsRevertStatus = async () => { | ||
setButtonDisabled(true); | ||
const response = await changeContentsStatus("REVERT"); | ||
// TODO: revalidate path | ||
toast({ | ||
variant: response.success ? "default" : "destructive", | ||
description: response.message, | ||
}); | ||
setButtonDisabled(false); | ||
}; | ||
|
||
return ( | ||
<div className="grid grid-cols-2 gap-4 p-4"> | ||
<Button onClick={handleNewsUpdateStatus} disabled={buttonDisabled}> | ||
NEWS UPDATE | ||
</Button> | ||
<Button onClick={handleNewsRevertStatus} disabled={buttonDisabled}> | ||
NEWS REVERT | ||
</Button> | ||
<Button onClick={handleContentsUpdateStatus} disabled={buttonDisabled}> | ||
CONTENTS UPDATE | ||
</Button> | ||
<Button onClick={handleContentsRevertStatus} disabled={buttonDisabled}> | ||
CONTENTS REVERT | ||
</Button> | ||
</div> | ||
); | ||
return <>{hasAdminPermission ? <ChangeStatusButtons /> : <Unauthorized />}</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,7 @@ | ||
import { env } from "@/env.mjs"; | ||
import { signInSchema } from "@/features/auth/schemas/sign-in-schema"; | ||
import prisma from "@/prisma"; | ||
import bcrypt from "bcryptjs"; | ||
import type { NextAuthConfig } from "next-auth"; | ||
import Credentials from "next-auth/providers/credentials"; | ||
// import GitHubProvider from "next-auth/providers/github"; | ||
|
||
// TODO: https://qiita.com/daiki7010/items/b15de9ef747f5b23c984 | ||
export const authConfig: NextAuthConfig = { | ||
secret: env.AUTH_SECRET, | ||
providers: [ | ||
// MEMO: for manual auth | ||
Credentials({ | ||
async authorize(credentials) { | ||
const parsedCredentials = signInSchema.safeParse(credentials); | ||
if (parsedCredentials.success) { | ||
const { username, password } = parsedCredentials.data; | ||
|
||
const user = await prisma.users.findUnique({ | ||
where: { username }, | ||
// MEMO: only allowed to select password here (for auth). See `src/prisma.ts` for more. | ||
select: { | ||
id: true, | ||
username: true, | ||
role: true, | ||
password: true, | ||
}, | ||
}); | ||
if (!user) return null; | ||
const passwordMatch = await bcrypt.compare(password, user.password); | ||
if (!passwordMatch) return null; | ||
|
||
return { id: user.id, role: user.role, username: user.username }; | ||
} | ||
return null; | ||
}, | ||
}), | ||
// MEMO: for GitHub Provider | ||
// GitHubProvider({ | ||
// clientId: env.GITHUB_CLIENT_ID, | ||
// clientSecret: env.GITHUB_CLIENT_SECRET, | ||
// }), | ||
], | ||
}; | ||
export default { | ||
providers: [Credentials /*GitHubProvider*/], | ||
} satisfies NextAuthConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
"use client"; | ||
type Props = { | ||
content: JSX.Element | JSX.Element[] | string; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
"use client"; | ||
import { Button } from "@/components/ui/button"; | ||
import { changeContentsStatus } from "@/features/update-status/actions/change-contents-status"; | ||
import { changeNewsStatus } from "@/features/update-status/actions/change-news-status"; | ||
import { useToast } from "@/hooks/use-toast"; | ||
import { useState } from "react"; | ||
|
||
export function ChangeStatusButtons() { | ||
const { toast } = useToast(); | ||
|
||
const [buttonDisabled, setButtonDisabled] = useState(false); | ||
|
||
const handleNewsUpdateStatus = async () => { | ||
setButtonDisabled(true); | ||
const response = await changeNewsStatus("UPDATE"); | ||
// TODO: revalidate path | ||
toast({ | ||
variant: response.success ? "default" : "destructive", | ||
description: response.message, | ||
}); | ||
setButtonDisabled(false); | ||
}; | ||
|
||
const handleNewsRevertStatus = async () => { | ||
setButtonDisabled(true); | ||
const response = await changeNewsStatus("REVERT"); | ||
// TODO: revalidate path | ||
toast({ | ||
variant: response.success ? "default" : "destructive", | ||
description: response.message, | ||
}); | ||
setButtonDisabled(false); | ||
}; | ||
|
||
const handleContentsUpdateStatus = async () => { | ||
setButtonDisabled(true); | ||
const response = await changeContentsStatus("UPDATE"); | ||
// TODO: revalidate path | ||
toast({ | ||
variant: response.success ? "default" : "destructive", | ||
description: response.message, | ||
}); | ||
setButtonDisabled(false); | ||
}; | ||
|
||
const handleContentsRevertStatus = async () => { | ||
setButtonDisabled(true); | ||
const response = await changeContentsStatus("REVERT"); | ||
// TODO: revalidate path | ||
toast({ | ||
variant: response.success ? "default" : "destructive", | ||
description: response.message, | ||
}); | ||
setButtonDisabled(false); | ||
}; | ||
|
||
return ( | ||
<div className="grid grid-cols-2 gap-4 p-4"> | ||
<Button onClick={handleNewsUpdateStatus} disabled={buttonDisabled}> | ||
NEWS UPDATE | ||
</Button> | ||
<Button onClick={handleNewsRevertStatus} disabled={buttonDisabled}> | ||
NEWS REVERT | ||
</Button> | ||
<Button onClick={handleContentsUpdateStatus} disabled={buttonDisabled}> | ||
CONTENTS UPDATE | ||
</Button> | ||
<Button onClick={handleContentsRevertStatus} disabled={buttonDisabled}> | ||
CONTENTS REVERT | ||
</Button> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters