gopinav / next-js-tutorials Goto Github PK
View Code? Open in Web Editor NEWSource code related to the Next.js tutorial series on YouTube
Home Page: next-js-misc.vercel.app
Source code related to the Next.js tutorial series on YouTube
Home Page: next-js-misc.vercel.app
Dear All,
I tried your code with next 13, next-auth 4 and typescript 5. Here is my code for Navbar.tsx
and [...nextauth].ts
.
Navbar.tsx
import Link from 'next/link';
import { signIn, signOut, useSession } from 'next-auth/react';
const Navbar = () => {
const { data: session, status } = useSession();
const loading = status === 'loading';
return (
<nav className="header">
<h1 className="logo">
<a href="#">{session ? `Welcome ${session.user?.name}` : 'NO LOGIN'}</a>
</h1>
<ul className={`main-nav ${!session && loading ? 'loading' : 'loaded'}`}>
<li>
<Link href="/">Home</Link>
</li>
<li>
<Link href="/dashboard-auth">Dashboard</Link>
</li>
<li>
<Link href="/blog-auth">Blog</Link>
</li>
{!loading && !session && (
<li>
<Link
href="/api/auth/signin"
onClick={(e) => {
e.preventDefault();
signIn('github', { redirect: false });
}}
>
Sign In
</Link>
</li>
)}
{session && (
<li>
<Link
href="/api/auth/signout"
onClick={(e) => {
e.preventDefault();
signOut({ redirect: false });
}}
>
Sign Out
</Link>
</li>
)}
</ul>
</nav>
);
};
export default Navbar;
[...nextauth].ts
import NextAuth from 'next-auth/next';
import GitHubProvider from 'next-auth/providers/github';
export default NextAuth({
providers: [
GitHubProvider({
clientId: process.env.GITHUB_ID!,
clientSecret: process.env.GITHUB_SECRET!,
}),
],
});
I noticed that, once signed in, the page gets reloaed thus loosing the state.
How could I avoid this reload? Thanks. Best regards.
ProductId doesn't show up on the page. Were there changes to router tasks since this tutorial been created?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.