11import React from "react" ;
22import { getCurrentUser } from "../../lib/session" ;
33import { redirect } from "next/navigation" ;
4- import { authOptions } from "../../lib/auth" ;
4+ import { authOptions , getSession } from "../../lib/auth" ;
55import Link from "next/link" ;
66import { siteConfig } from "../../config/site" ;
7- import { signOut } from "next-auth/react" ;
87import SignOutButton from "../../components/signout-button/page" ;
98
109export const metadata = {
@@ -13,11 +12,17 @@ export const metadata = {
1312} ;
1413
1514async function getUsers ( ) : Promise < any | null > {
15+ const session = await getSession ( ) ;
16+ console . log ( "session" , session ) ;
17+
1618 try {
1719 const response = await fetch ( `${ siteConfig . localApi } /users` , {
1820 next : {
1921 revalidate : 60 ,
2022 } ,
23+ headers : {
24+ Authorization : `Bearer ${ session ?. user ?. token } ` ,
25+ } ,
2126 } ) ;
2227
2328 // if (!response?.ok) {
@@ -34,18 +39,17 @@ async function getUsers(): Promise<any | null> {
3439}
3540
3641export default async function DashboardPage ( ) {
37- const users = await getUsers ( ) ;
3842 const user = await getCurrentUser ( ) ;
43+ const users = await getUsers ( ) ;
3944
40- if ( ! user ) {
41- redirect ( authOptions ?. pages ?. signIn || "/auth/signin" ) ;
42- }
4345 return (
4446 < main className = { `flex min-h-screen flex-col items-center p-4` } >
4547 < header className = "container z-40 bg-background" >
4648 < div className = "flex h-20 items-center justify-between py-6" >
4749 < nav >
48- < SignOutButton className = { `absolute left-5 top-5 bg-teal-500 hover:bg-teal-700 text-white font-bold rounded-sm min-w-[70px] text-center` } />
50+ < SignOutButton
51+ className = { `absolute left-5 top-5 bg-teal-500 hover:bg-teal-700 text-white font-bold rounded-sm min-w-[70px] text-center` }
52+ />
4953 </ nav >
5054 </ div >
5155 </ header >
0 commit comments