Skip to content

Commit

Permalink
Merge pull request #37 from ArhanAnsari/ArhanAnsari-patch-1
Browse files Browse the repository at this point in the history
Update page.tsx
  • Loading branch information
ArhanAnsari authored Sep 22, 2024
2 parents 2293f21 + 8fa2242 commit fad45bc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
19 changes: 10 additions & 9 deletions app/auth/signin/page.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
"use client";
import { signIn } from "next-auth/react";
import { signIn, useSession } from "next-auth/react";
import { useRouter } from "next/navigation";
import { useState, useEffect } from "react";
import { useState } from "react";
import { ToastContainer, toast } from "react-toastify";
import { getUserData } from "@/firebaseFunctions"; // Import Firebase function to get user data
import "react-toastify/dist/ReactToastify.css";

export default function SignIn() {
const router = useRouter();
const { data: session } = useSession(); // Get session data
const [loading, setLoading] = useState(false);

const handleSignIn = async () => {
setLoading(true);
try {
const result = await signIn("google");
const result = await signIn("google", { redirect: false });

if (result?.error) {
throw new Error(result.error);
}

// Fetch user data after sign-in
const user = result?.user;
if (user && user.email) {
const userData = await getUserData(user.email);
// Wait for the session to update
const userEmail = session?.user?.email;

if (userEmail) {
const userData = await getUserData(userEmail);
if (userData) {
console.log(`User Plan: ${userData.plan}`);
console.log(`Max Requests Allowed: ${userData.requestCount}`);
console.log(`Requests Made: ${userData.requestCount}`);

// Optionally show a toast with this information
toast.success(`Welcome back! You are on the ${userData.plan} plan.`);
}
}
Expand Down
16 changes: 8 additions & 8 deletions app/auth/signup/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
"use client";
import { signIn } from "next-auth/react";
import { signIn, useSession } from "next-auth/react";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { ToastContainer, toast } from "react-toastify";
Expand All @@ -9,26 +9,26 @@ import "react-toastify/dist/ReactToastify.css";

export default function SignUp() {
const router = useRouter();
const { data: session } = useSession(); // Get session data
const [loading, setLoading] = useState(false);

const handleSignUp = async () => {
setLoading(true);
try {
const result = await signIn("google");
const result = await signIn("google", { redirect: false });
if (result?.error) {
throw new Error(result.error);
}

// Fetch user data after sign-up
const user = result?.user;
if (user && user.email) {
const userData = await getUserData(user.email);
// Wait for the session to update
const userEmail = session?.user?.email;

if (userEmail) {
const userData = await getUserData(userEmail);
if (userData) {
console.log(`User Plan: ${userData.plan}`);
console.log(`Max Requests Allowed: ${userData.requestCount}`);
console.log(`Requests Made: ${userData.requestCount}`);

// Optionally show a toast with this information
toast.success(`Welcome! You are on the ${userData.plan} plan.`);
}
}
Expand Down

0 comments on commit fad45bc

Please sign in to comment.