© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•13mo ago
EnderTheNetrunner

Client Side Oauth?

I'm trying to work out a client side PKCE workflow for the sake of integrating Notion Oauth, specifically. Using Next.js. Main concern is whether PKCE actually needs server-side code to work, or if I can hack it client side.

Reason for this is I have Next.js exporting to static, and I don't have an easy way of supporting API routes with it because I have another framework handling the REST API (yes, yes, silly decision, I know).

Here's the code I have so far:

'use client';

import { useSearchParams, useRouter } from 'next/navigation';
import { Suspense } from 'react';

import Loading from '@app/loading';
import { Endpoints } from '@coursefull/enums';
import { supabase } from '@lib/supabase';

async function AuthCallback() {
    const router = useRouter();
    const searchParams = useSearchParams();
    const code = searchParams.get('code');
    const next = searchParams.get('next') ?? '/';

    if (!code) {
        throw new Error(`Auth code not present.`);
    }

    const { error } = await supabase.auth.exchangeCodeForSession(code);

    if (error) {
        throw error;
    }

    router.push(Endpoints.DASHBOARD);

    return <div></div>;
}

export default function Page() {
    return (
        <Suspense fallback={<Loading />}>
            <AuthCallback />
        </Suspense>
    );
}
'use client';

import { useSearchParams, useRouter } from 'next/navigation';
import { Suspense } from 'react';

import Loading from '@app/loading';
import { Endpoints } from '@coursefull/enums';
import { supabase } from '@lib/supabase';

async function AuthCallback() {
    const router = useRouter();
    const searchParams = useSearchParams();
    const code = searchParams.get('code');
    const next = searchParams.get('next') ?? '/';

    if (!code) {
        throw new Error(`Auth code not present.`);
    }

    const { error } = await supabase.auth.exchangeCodeForSession(code);

    if (error) {
        throw error;
    }

    router.push(Endpoints.DASHBOARD);

    return <div></div>;
}

export default function Page() {
    return (
        <Suspense fallback={<Loading />}>
            <AuthCallback />
        </Suspense>
    );
}


And the Supabase client mentioned in
@lib/supabase
@lib/supabase
:
import { createClient } from '@supabase/supabase-js';

const AUTH_TOKEN_STORAGE_KEY = 'sb-coursefull-auth-token';

const supabase = createClient(
    process.env.NEXT_PUBLIC_SUPABASE_URL || '',
    process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || '',
    {
        auth: {
            flowType: 'pkce',
            storageKey: AUTH_TOKEN_STORAGE_KEY,
        },
    }
);

export default supabase;
export { AUTH_TOKEN_STORAGE_KEY };
import { createClient } from '@supabase/supabase-js';

const AUTH_TOKEN_STORAGE_KEY = 'sb-coursefull-auth-token';

const supabase = createClient(
    process.env.NEXT_PUBLIC_SUPABASE_URL || '',
    process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || '',
    {
        auth: {
            flowType: 'pkce',
            storageKey: AUTH_TOKEN_STORAGE_KEY,
        },
    }
);

export default supabase;
export { AUTH_TOKEN_STORAGE_KEY };
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Client side user
SupabaseSSupabase / help-and-questions
3y ago
Can you mix server-side client with client-side client (NextJS)?
SupabaseSSupabase / help-and-questions
13mo ago
query exposed on client side
SupabaseSSupabase / help-and-questions
12mo ago
NextJS: User data client side?
SupabaseSSupabase / help-and-questions
2y ago