-
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.
feat: 메인페이지에서 서버사이드에서 유저 정보 불러오도록 수정
- Loading branch information
Showing
4 changed files
with
85 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
'use client' | ||
|
||
import { useSession } from 'next-auth/react' | ||
import { IntroPage } from './intro.page' | ||
import DashboardPage from './dashboard.page' | ||
import { PrismaClient } from '@repo/database' | ||
import { getServerSession } from 'next-auth' | ||
import { redirect } from 'next/navigation' | ||
|
||
const prisma = new PrismaClient() | ||
|
||
export default function MainPage() { | ||
const { data: session } = useSession() //세션 정보를 가져옴 | ||
export default async function MainPage() { | ||
const session = await getServerSession() //세션 정보를 가져옴 | ||
console.log(session?.user?.image) | ||
|
||
if (!session?.user) { | ||
return <IntroPage /> | ||
if (session?.user) { | ||
const user = await prisma.user.findUnique({ | ||
where: { email: session.user.email ?? undefined }, | ||
}) | ||
|
||
if (!user) return redirect('/login') | ||
|
||
return <DashboardPage user={user} /> | ||
} else { | ||
return <DashboardPage /> | ||
return <IntroPage /> | ||
} | ||
} |
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
61 changes: 61 additions & 0 deletions
61
packages/database/prisma/migrations/20240804204353_/migration.sql
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,61 @@ | ||
/* | ||
Warnings: | ||
- The primary key for the `User` table will be changed. If it partially fails, the table could be left without primary key constraint. | ||
- You are about to drop the column `id` on the `User` table. All the data in the column will be lost. | ||
- The required column `userId` was added to the `User` table with a prisma-level default value. This is not possible if the table is not empty. Please add this column as optional, then populate it before making it required. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE `User` DROP PRIMARY KEY, | ||
DROP COLUMN `id`, | ||
ADD COLUMN `userId` VARCHAR(191) NOT NULL, | ||
ADD PRIMARY KEY (`userId`); | ||
|
||
-- CreateTable | ||
CREATE TABLE `Meal` ( | ||
`mealId` VARCHAR(191) NOT NULL, | ||
`date` DATETIME(3) NOT NULL, | ||
`type` VARCHAR(191) NOT NULL, | ||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), | ||
`updatedAt` DATETIME(3) NOT NULL, | ||
|
||
PRIMARY KEY (`mealId`) | ||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
|
||
-- CreateTable | ||
CREATE TABLE `MealItem` ( | ||
`mealItemId` VARCHAR(191) NOT NULL, | ||
`mealId` VARCHAR(191) NOT NULL, | ||
`imageUrl` VARCHAR(191) NOT NULL, | ||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), | ||
`updatedAt` DATETIME(3) NOT NULL, | ||
|
||
INDEX `MealItem_mealId_idx`(`mealId`), | ||
PRIMARY KEY (`mealItemId`) | ||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
|
||
-- CreateTable | ||
CREATE TABLE `MealItemAnalysis` ( | ||
`mealItemAnalysisId` VARCHAR(191) NOT NULL, | ||
`mealItemId` VARCHAR(191) NOT NULL, | ||
`kcal` DOUBLE NOT NULL, | ||
`carbohydrate` DOUBLE NOT NULL, | ||
`sugars` DOUBLE NOT NULL, | ||
`fat` DOUBLE NOT NULL, | ||
`protein` DOUBLE NOT NULL, | ||
`calcium` DOUBLE NOT NULL, | ||
`phosphorus` DOUBLE NOT NULL, | ||
`natrium` DOUBLE NOT NULL, | ||
`kalium` DOUBLE NOT NULL, | ||
`magnesium` DOUBLE NOT NULL, | ||
`iron` DOUBLE NOT NULL, | ||
`zinc` DOUBLE NOT NULL, | ||
`cholesterol` DOUBLE NOT NULL, | ||
`transfat` DOUBLE NOT NULL, | ||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), | ||
`updatedAt` DATETIME(3) NOT NULL, | ||
|
||
INDEX `MealItemAnalysis_mealItemId_idx`(`mealItemId`), | ||
PRIMARY KEY (`mealItemAnalysisId`) | ||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; |