-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30dfd41
commit 61fdca1
Showing
14 changed files
with
159 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import NextAuth from "next-auth" | ||
|
||
export const { handlers, signIn, signOut, auth } = NextAuth({ | ||
providers: [], | ||
}) | ||
export async function getServerSideProps(context: { req: { cookies: any; }; }) { | ||
console.log('Cookies in getServerSideProps:', context.req.cookies); | ||
return { props: {} }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use server' | ||
import { GoogleAuthProvider, signOut, signInWithPopup } from "firebase/auth"; | ||
import { auth } from "../lib/firebase"; | ||
import toast from "react-hot-toast"; | ||
import Cookies from "js-cookie"; | ||
import { useRouter } from "next/navigation"; | ||
import { setCookie } from "cookies-next"; | ||
import { cookies } from "next/headers"; | ||
|
||
const SignUpAction = () => { | ||
const provider = new GoogleAuthProvider(); | ||
// const router = useRouter(); | ||
const cook = cookies() | ||
signInWithPopup(auth, provider) | ||
.then((res) => { | ||
const credential = GoogleAuthProvider.credentialFromResult(res); | ||
const token = credential?.accessToken; | ||
const user = res.user; | ||
console.log(user); | ||
console.log(token); | ||
if (token) { | ||
console.log("Token received from Firebase:", token); | ||
|
||
// Set the token as an HTTP-only cookie | ||
// setCookie('token', token, { | ||
// maxAge: 7 * 24 * 60 * 60, // 7 days | ||
// path: '/', | ||
// secure: process.env.NODE_ENV === 'production', | ||
// httpOnly: true, | ||
// sameSite: 'strict' | ||
// }); | ||
cook.set({ | ||
name: "token", | ||
value: token, | ||
path: "/", | ||
httpOnly: true, | ||
}); | ||
|
||
console.log("Cookie set with token"); | ||
|
||
// window.localStorage.setItem("user", JSON.stringify(user)); | ||
toast.success("SignIn successful"); | ||
// router.push("/chat"); | ||
} else { | ||
console.error("No token received from Firebase"); | ||
toast.error("SignIn failed: No token received"); | ||
} | ||
}) | ||
.catch((error) => { | ||
const errorCode = error.code; | ||
const errorMessage = error.message; | ||
const email = error.customData.email; | ||
const credential = GoogleAuthProvider.credentialFromError(error); | ||
console.error(error, errorCode, errorMessage, email, credential); | ||
toast.error("SignIn failed"); | ||
}); | ||
}; | ||
|
||
export default SignUpAction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters