🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)
🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)

🔧 Programmierung 🕛 kürzlich 4 Min Lesezeit
0

NextAuth.js authentication with Github and Google in NextJs

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

NextAuth aims to make authentication simple, yet secure in Next.js apps. it handles automatically practices like passwordless flow, scoping access and more.



With it you can simply get authenticated through your existing logins from different platforms like Google, Atlassian, github, etc.






  • Next, recover the clientId highlighted below and then generate client secret.





  • Then, Fill in the form like this:







  • NOTE:




    • replace "weiterbildung" by the name of your project

    • Go to your existing .env file in which you'll save those keys and more sensitive informations, create it if it doesn't exist in your root directory.






    Step 2. Create the Authentication API route




    • In App Create the directory api/[...nextauth]/route.ts and implement the authentication API route the following way:




    CODE
    // route.ts

    import { authOptions } from "@/lib/authOptions";
    import NextAuth from "next-auth";
    import { AuthOptions } from "next-auth";

    const handler = NextAuth(authOptions as AuthOptions);

    export { handler as GET, handler as POST };







    • Create a provider that will wrap your system, to make all its props available like a context, in your lib directory, create sessionWrapper.tsx where you'll do:




    CODE
    //sessionWrapper.tsx

    "use client"

    import { SessionProvider } from "next-auth/react"

    const SessionWrapper = ({children}: {children: React.ReactNode}) => {
    return <SessionProvider>{children}</SessionProvider>
    }

    export default SessionWrapper;







    • implement the SessionWrapper component in layout.tsx after importing it and wrap the layout elements within it, its return should look like this:




    CODE
    //layout.tsx
    import SessionWrapper from "../lib/sessionWrapper";

    //...some code
    return (
    <SessionWrapper> //here you are
    <html lang="en">
    <body
    className={`${geistSans.variable} ${geistMono.variable} antialiased`}
    >
    <ClientLayout session={session}>{children}</ClientLayout>
    </body>
    </html>
    </SessionWrapper> //here you are
    );









    Step 3. Set up the connexion between your system and the google and github providers




    • In your log-in page or component do the following modification:




    CODE
    //logIn.tsx


    "use client"

    import { signIn, useSession } from 'next-auth/react';

    export default function Login() {
    const { data: session } = useSession();

    if(session) {
    console.log('session', session);
    }


    return (
    <div>
    <button
    type="button"
    onClick={() => signIn('github')}
    className="w-full py-2 my-2 border border-red-500"
    >Login with Github
    </button>

    <button
    type="button"
    onClick={() => {signIn('google')}}
    className="w-full py-2 my-2 border border-red-500"
    >Login with Google
    </button>
    </div>
    );
    }







    • In your log-out component do the following modification:




    CODE
    //signOut.tsx


    import { signOut } from 'next-auth/react';

    export default function Login() {
    return (
    <div>
    <button
    type="button"
    onClick={() => signOut()}
    className="w-full py-2 my-2 border border-red-500"
    >Log out
    </button>

    </div>
    );
    }






    RESULT WITH GOOGLE:




  • You can choose to get the JWT(Json Web Token) instead of a row object if you want to get your backend involved.


  • Vollständiger Original-Bericht
    Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
    ↗ Original-Artikel auf dev.to lesen
    Wie bewertest du diesen Beitrag?
    1 Klick Feedback
    Teilen mit Netzwerk & Team:

    Community-Analysen & Experten-Meinungen 0

    Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
    Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
    Community Pulse: Relevanz-Einschätzung
    1 Klick Experten-Votum
    🔴 Akute Relevanz 0%
    🟡 In Evaluierung 0%
    🟢 Keine Auswirkung 0%
    Spannende Innovation 0%
    Verwandte Story-Cluster & Quellen (Vektor-KI)
    Port 8095 Engine
    3 Quellen
    GPT-6 Astra Release Today? OpenAI’s Next Major AI Model Is Almost Here
    1 Quelle
    Apple accuses OpenAI of destroying evidence as trade-secrets fight intensifies
    1 Quelle
    Major AI platforms go down in unprecedented simultaneous outage
    Ähnliche Beiträge
    🔍 Verwandte News

    Auch interessante Nachrichten NextAuth.js authentication with Github and Google in NextJs

    Thematisch verwandte Begriffe: NextAuthjs, authentication, with, Github · 6 Treffer

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...