Skip to content

Commit

Permalink
Merge pull request #15 from the-collab-lab/setup-firebase-auth
Browse files Browse the repository at this point in the history
add firebase config
  • Loading branch information
redapy authored Aug 10, 2024
2 parents b8b924e + e25a552 commit e07fb18
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 36 deletions.
57 changes: 40 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/api/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { getAuth } from 'firebase/auth';

// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: 'FILL_ME_IN',
authDomain: 'FILL_ME_IN',
projectId: 'FILL_ME_IN',
storageBucket: 'FILL_ME_IN',
messagingSenderId: 'FILL_ME_IN',
appId: 'FILL_ME_IN',
apiKey: 'AIzaSyC4rKWbeuFoe8URakxp2oei_GIzqsSWFrg',
authDomain: 'tcl-79-smart-shopping-list.firebaseapp.com',
projectId: 'tcl-79-smart-shopping-list',
storageBucket: 'tcl-79-smart-shopping-list.appspot.com',
messagingSenderId: '141815834662',
appId: '1:141815834662:web:a40412a9106b2a470f9ee7',
};

// Initialize Firebase
Expand Down
4 changes: 2 additions & 2 deletions src/api/useAuth.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react';
import { auth } from './config.js';
import { GoogleAuthProvider, signInWithRedirect } from 'firebase/auth';
import { GoogleAuthProvider, signInWithPopup } from 'firebase/auth';
import { addUserToDatabase } from './firebase.js';

/**
Expand All @@ -11,7 +11,7 @@ import { addUserToDatabase } from './firebase.js';
export const SignInButton = () => (
<button
type="button"
onClick={() => signInWithRedirect(auth, new GoogleAuthProvider())}
onClick={() => signInWithPopup(auth, new GoogleAuthProvider())}
>
Sign In
</button>
Expand Down
12 changes: 1 addition & 11 deletions src/views/Layout.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
import { Outlet } from 'react-router-dom';

import './Layout.css';
import { auth } from '../api/config.js';
import { useAuth, SignInButton, SignOutButton } from '../api/useAuth.jsx';

/**
* TODO: The links defined in this file don't work!
Expand All @@ -13,20 +12,11 @@ import { useAuth, SignInButton, SignOutButton } from '../api/useAuth.jsx';
*/

export function Layout() {
const { user } = useAuth();
return (
<>
<div className="Layout">
<header className="Layout-header">
<h1>Smart shopping list</h1>
{!!user ? (
<div>
<span>Signed in as {auth.currentUser.displayName}</span> (
<SignOutButton />)
</div>
) : (
<SignInButton />
)}
</header>
<main className="Layout-main">
<Outlet />
Expand Down

0 comments on commit e07fb18

Please sign in to comment.