-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
84 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
import type { Session, User } from '@prisma/client' | ||
import type { GetServerSidePropsContext, NextApiRequest, NextApiResponse } from 'next' | ||
import { unstable_getServerSession } from 'next-auth' | ||
import { getAuthOptions } from '~/pages/api/auth/[...nextauth]' | ||
|
||
export async function getAuth( | ||
req: NextApiRequest, | ||
res: NextApiResponse, | ||
req: NextApiRequest | GetServerSidePropsContext['req'], | ||
res: NextApiResponse | GetServerSidePropsContext['res'], | ||
) { | ||
const authOptions = await getAuthOptions() | ||
const session = await unstable_getServerSession(req, res, authOptions) | ||
const session = (await unstable_getServerSession(req, res, authOptions)) as unknown as (Session & { user: User }) | ||
if (!session) { | ||
res.status(401).json({ message: 'Please logged in.' }) | ||
if ((res as NextApiResponse).status) (res as NextApiResponse).status(401).json({ message: 'Please logged in.' }) | ||
return false | ||
} | ||
return true | ||
return session | ||
} |
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
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,14 @@ | ||
-- CreateTable | ||
CREATE TABLE "UsersOnProjects" ( | ||
"userId" TEXT NOT NULL, | ||
"projectId" INTEGER NOT NULL, | ||
"assignedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "UsersOnProjects_pkey" PRIMARY KEY ("userId","projectId") | ||
); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "UsersOnProjects" ADD CONSTRAINT "UsersOnProjects_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "UsersOnProjects" ADD CONSTRAINT "UsersOnProjects_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
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