© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•7mo ago•
25 replies
Jonathan

Supabase getUser() returns undefined

Code: https://github.com/jwaddell10/PracticeScheduler

Hello! Currently building a React Native, Expo app with an express backend, using supabase auth.

I am able to (I believe) log a user in, when I create my session and export it throughout the app with useContext I'm able to see an access token, I pass this token to my backend in my authorization header as a bearer token
Authorization: `Bearer ${session?.access_token}
Authorization: `Bearer ${session?.access_token}
`, and it logs on my backend as well

However, when I call getUser(token) server side with express

const { data, error } = await supabase.auth.getUser(token);
const { data, error } = await supabase.auth.getUser(token);

I get this error
Auth error: TypeError: Cannot read properties of undefined (reading 'getUser')
Auth error: TypeError: Cannot read properties of undefined (reading 'getUser')

I've reread the docs, and it says if you pass in access token it should be able to get the user. I've tried removing the token from getUser call and it has the same result. Any ideas?

I tested my RLS policies with impersonation and it worked, so I think it's because getUser is undefined and not finding the user that my issue is happening

const authenticateUser = async (req, res, next) => {
    const authHeader = req.headers.authorization;

    if (!authHeader || !authHeader.startsWith("Bearer ")) {
        return res
            .status(401)
            .json({ error: "Missing or malformed auth header" });
    }

    const token = authHeader.split(" ")[1];

    try {
        const { data, error } = await supabase.auth.getUser(token);
        if (error || !data?.user) {
            console.error("Auth verification failed:", error);
            return res.status(401).json({
                error: "Invalid or expired token",
                details: error?.message,
            });
        }

        req.user = data.user; // make user available to route handlers
        next();
    } catch (err) {
        console.error("Auth error:", err);
        return res.status(401).json({ error: "Authentication failed" });
    }
};
const authenticateUser = async (req, res, next) => {
    const authHeader = req.headers.authorization;

    if (!authHeader || !authHeader.startsWith("Bearer ")) {
        return res
            .status(401)
            .json({ error: "Missing or malformed auth header" });
    }

    const token = authHeader.split(" ")[1];

    try {
        const { data, error } = await supabase.auth.getUser(token);
        if (error || !data?.user) {
            console.error("Auth verification failed:", error);
            return res.status(401).json({
                error: "Invalid or expired token",
                details: error?.message,
            });
        }

        req.user = data.user; // make user available to route handlers
        next();
    } catch (err) {
        console.error("Auth error:", err);
        return res.status(401).json({ error: "Authentication failed" });
    }
};
GitHub
GitHub - jwaddell10/PracticeScheduler
Contribute to jwaddell10/PracticeScheduler development by creating an account on GitHub.
GitHub - jwaddell10/PracticeScheduler
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
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

supabase auth.getUser always returns null
SupabaseSSupabase / help-and-questions
4y ago
Supabase JS RC Insert returns undefined but database have result?
SupabaseSSupabase / help-and-questions
4y ago
supabaseClient.auth.getUser returns null even if authenticated.
SupabaseSSupabase / help-and-questions
6mo ago
Rate limiting on supabase.auth.getUser(token)
SupabaseSSupabase / help-and-questions
4w ago