Skip to content

Commit

Permalink
feat: 메인페이지에서 서버사이드에서 유저 정보 불러오도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ArpaAP committed Aug 4, 2024
1 parent 9bdde4c commit 1cec2ac
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 13 deletions.
12 changes: 8 additions & 4 deletions apps/web/src/app/dashboard.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
Legend,
} from 'chart.js'
import { useSession } from 'next-auth/react'
import { User } from '@prisma/client'

Chart.register(
CategoryScale,
Expand All @@ -34,9 +35,12 @@ Chart.register(
Legend
)

export default function DashboardPage() {
interface DashboardPageProps {
user: User
}

export default function DashboardPage({ user }: DashboardPageProps) {
const { data: session } = useSession() //세션 정보를 가져옴
console.log(session?.user?.image)

return (
<MainLayout>
Expand Down Expand Up @@ -66,12 +70,12 @@ export default function DashboardPage() {
<div className="w-1/5">
<Image
className="rounded-full"
src={`https://picsum.photos/200/200?random=5`}
src={session?.user?.image ?? ''}
alt="random"
width={120}
height={120}
/>
<div className="text-2xl font-bold py-6">황부연</div>
<div className="text-2xl font-bold py-6">{user.name}</div>
<div className="flex flex-col gap-1">
<div className="flex justify-between gap-4">
<div className="text-gray-600">분석한 개수</div>
Expand Down
24 changes: 16 additions & 8 deletions apps/web/src/app/page.tsx
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 />
}
}
1 change: 0 additions & 1 deletion apps/web/src/lib/firebase/firebaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const firebaseConfig = {
appId: process.env.FIREBASE_APP_ID,
measurementId: process.env.FIREBASE_MEASUREMENT_ID,
}
console.log(firebaseConfig)
// Initialize Firebase
const app = initializeApp(firebaseConfig)
export const storage = getStorage(app)
61 changes: 61 additions & 0 deletions packages/database/prisma/migrations/20240804204353_/migration.sql
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;

0 comments on commit 1cec2ac

Please sign in to comment.