Skip to content

Commit

Permalink
Update fetch session user
Browse files Browse the repository at this point in the history
  • Loading branch information
thebkht committed Oct 30, 2023
1 parent 474474f commit 280fe28
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
9 changes: 3 additions & 6 deletions app/api/session/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ import postgres from "@/lib/postgres";
import { getServerSession } from "next-auth";
import { NextRequest, NextResponse } from "next/server";

export async function GET(req: NextRequest) {
export async function POST(req: NextRequest) {
try {
const session = await getServerSession(config)
if (!session) {
return NextResponse.json({ error: "Not authorized" }, { status: 401 })
}
const { user } = session
const { user } = await req.json();


const result = await postgres.user.findFirst({
where: {
Expand Down
2 changes: 0 additions & 2 deletions components/feed/get-feed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use server'
import postgres from "@/lib/postgres";
import { getSessionUser } from "../get-session-user";
import { getFeed } from "@/lib/prisma/feed";

export const fetchFeed = async ({ page = 0, tag }: { page?: number, tag?: string | undefined }) => {
Expand Down
23 changes: 15 additions & 8 deletions components/get-session-user.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
'use server'
import { config } from "@/app/auth";
import postgres from "@/lib/postgres";
import { tr } from "date-fns/locale";
import { getServerSession } from "next-auth";
import { cache } from "react";

import { config } from "@/app/auth"
import { getServerSession } from "next-auth"

export async function getSessionUser() {
const session = await fetch('/api/session', {
method: 'GET',
const sessionUser = await getServerSession(config)
if (!sessionUser) {
return null
}
const { user } = sessionUser
const session = await fetch(`${process.env.DOMAIN}/api/session`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ user })
}).then((res) => res.json())

console.log(session)
if (session.error) {
return null
}
return session.user
}

0 comments on commit 280fe28

Please sign in to comment.