Skip to content

Commit

Permalink
fix: login google auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Troleomotor10 committed Nov 7, 2024
1 parent 9e8dab5 commit df38131
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/components/UserInfo.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import Link from 'next/link';
import { LogIn } from 'lucide-react';
import { authService } from '@/lib/service';
import { useSession } from '../context/SessionProvider';

export default function UserProfile() {
const { user } = useSession();
export default function UserProfile({ user }) {
const handleLogout = async () => {
const response = await authService.signOut();
if (!response.error) {
Expand Down
21 changes: 17 additions & 4 deletions src/components/layout/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {
CarTaxiFront,
} from 'lucide-react';
import UserInfo from '../UserInfo';
import { useSession } from '../../context/SessionProvider';
import { useState, useEffect } from 'react';
import { supabase } from '@/lib/supabase/client';

const menuItems = [
{
Expand Down Expand Up @@ -146,7 +147,19 @@ const menuItems = [
export default function Sidebar({ isOpen, toggle }) {
const router = useRouter();
const pathname = usePathname();
const session = useSession();

const [user, setUser] = useState(null);

useEffect(() => {
const fetchUser = async () => {
const {
data: { user },
} = await supabase.auth.getUser();
setUser(user);
};
fetchUser();
}, []);

return (
<>
{/* Quitamos el overlay con fondo negro */}
Expand Down Expand Up @@ -179,7 +192,7 @@ export default function Sidebar({ isOpen, toggle }) {
<nav className="p-4 flex-1 overflow-y-auto">
<div className="space-y-2">
{menuItems.map((item) =>
(session && session.user && session.user.email && item.isAuth) || !item.isAuth ? (
(user && user.email && item.isAuth) || !item.isAuth ? (
item.isHref ? (
<button
key={item.path}
Expand Down Expand Up @@ -235,7 +248,7 @@ export default function Sidebar({ isOpen, toggle }) {

{/* User info and login */}
<div className="p-4">
<UserInfo />
<UserInfo user={user} />
</div>

{/* Toggle button for desktop */}
Expand Down

0 comments on commit df38131

Please sign in to comment.