Next.js Discord

Discord Forum

App router, Next Auth, existing express backend implementing discord oauth2

Chinese perch posted this in #help-forum
Open in Discord
Chinese perchOP
Hello, I have an existing express backend that handles discord oauth2 using passport, which provides a session cookie.

What would be an appropriate way to connect this to a new next 13 project using the app router and next auth? Resources related to custom backends handling auth seem to be outdated and varying in opinion:

1) Migrate authentication to next server layer and call express backend for business logic
2) Next calls oauth2 provider (discord), sends token to express, express verifies validity with auth provider and retrieves user details, returns signed cookie to frontend.
3) Configure next auth to make use of existing express backend the way it is.

The issue I'm therefore having is both which approach might be suitable, and that I would not know what steps to take for options 2 and 3.

Thanks in advance to anyone that is able to provide guidance.

5 Replies

Chinese perchOP
Unsure what the etiquette is here for bumping posts, if anyone would like me to add additional info please let me know
yes you did it right, you may bump posts like this once a day. i don't know next-auth so i can't help though and can only say this much
Chinese perchOP
Still an open query. Another consideration is that I'll need to send SSEs from the existing backend to the Next frontend. Is using the Next API as a proxy for this feasible? As this would influence direction
as for SSE, Vercel AI SDK is used as a proxy for Open AI API, which returns response as SSE. It has to be hosted in Edge Runtime, which is Cloudflare Worker., where it's billed by CPU time instead of walltime.
export const runtime = 'edge'

export async function POST(req: Request) {
    const {messages} = await req.json()

    try {
        const response = await openai.createChatCompletion({
            model: 'gpt-3.5-turbo',
            top_p: 0.75,
            // temperature: 0.9,        
            stream: true,

        const stream = OpenAIStream(response)
        return new StreamingTextResponse(stream)

    } catch (error) {
        return new Response(JSON.stringify({error: 'An error occurred while creating the chat completion'}), {status: 500})