nestjs-supabase-auth icon indicating copy to clipboard operation
nestjs-supabase-auth copied to clipboard

Update supabase-js to latest version -> fixed https://github.com/hiro1107/nestjs-supabase-auth/issues/7 + Code cleanup

Open Gamekohl opened this issue 2 years ago • 7 comments
trafficstars

I've updated supbabase-js to the latest version to resolve this bug (https://github.com/hiro1107/nestjs-supabase-auth/issues/7). Also I cleaned up the code, hence removed the validateSupabaseResponse function and put the code directly into the validate function.

Gamekohl avatar Sep 25 '23 21:09 Gamekohl

It works

NicolasDiazDuarte avatar Nov 09 '23 21:11 NicolasDiazDuarte

Any reason why this shouldn't get merged? Seems like a useful fix.

gamedevsam avatar Dec 29 '23 19:12 gamedevsam

waiting to merge, any update ?

hmtcelik avatar Jan 04 '24 11:01 hmtcelik

@hiro1107 Need this one to be merged asap

farischt avatar Jan 08 '24 23:01 farischt

Looks like this repo maybe stale, it's worth trying to make a fork the canonical / active version of the package. We might be able to reach out to NPM to swap owners of the library, or we could just publish it as a new package. Thoughts?

gamedevsam avatar Jan 22 '24 22:01 gamedevsam

@gamedevsam Created my own guard if someone needs it:

auth.guard.ts

@Injectable()
export class GqlAuthGuard implements CanActivate {
  public async canActivate(context: ExecutionContext): Promise<boolean> {
    const ctx = GqlExecutionContext.create(context);

    const request = ctx.getContext().req as GraphQLRequest;

    const { authorization } = request.headers;
    if (!authorization || authorization.trim() === '') {
      throw new UnauthorizedException('Missing authorization header');
    }

    const jwt = authorization.replace(/bearer/gim, '').trim();
    const { data, error } = await supabase.auth.getUser(jwt);

    if (error) {
      throw new UnauthorizedException('Invalid or expired token');
    }

    request.user = data.user;
    return true;
  }
}

auth.decorator.ts

import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { GqlExecutionContext } from '@nestjs/graphql';

export const GqlAuthUser = createParamDecorator(
  (_data: unknown, context: ExecutionContext) => {
    const ctx = GqlExecutionContext.create(context);
    return ctx.getContext().req?.user;
  },
);

fyi supabase is created in another folder Feel free to ping me if needed !

farischt avatar Jan 22 '24 22:01 farischt

forked and merged at https://github.com/tgirotto/nestjs-supabase-auth-v2

tgirotto avatar Feb 03 '24 15:02 tgirotto

@tgirotto Thank you for creating the PR, and I'm sorry it took such a long time to review. I plan to add another maintener to this repo so the repo will be keep updated.

hiro1107 avatar Jun 18 '24 10:06 hiro1107