Is it possible to use Clerk on NestJs? I have been unable to find any documentation towards this. If it is possible and anyone has examples, please feel welcome to share.
Thanks
Clerk’s node sdk should be enough to create a strategy and authguard in Nest. An authguard is just a piece of middleware that implements a strategy you define. Essentially you capture the jwt that you should be sending in the header (Bearer) to each request on your api.
I have used the Clerk-node-sdk in a project with a GraphQL Yoga server and it was pretty straight forward. Clerk has a validate function on their SDK which is what you will use in your Nest SDK to validate the jwt being sent from your frontend. I’d start there and work within a strategy with Nest.
in app.controller.ts :
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
async getClientList() {
return await this.appService.getClientList();
}
}
in app.service.ts :
import { Injectable} from '@nestjs/common';
import { Clerk } from '@clerk/clerk-sdk-node';
@Injectable()
export class AppService {
private clerkClient;
constructor() {
this.clerkClient = Clerk({
secretKey: 'sk_test_yourApiKey',
});
}
async getClientList() {
return await this.clerkClient.users.getUserList();
}
}
in app.module.ts :
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
imports: [],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
then start ur server and go to your localhost : me is http://localhost:3002/ but http://localhost:3000/ by default and adapt to your route me for this moment i have just app.service.ts i don't have created route yet
nestjs is a nodejs framework
so anything you can do in nodejs is possible in nestjs.
Follow Clerk nodejs's docs and you should be fine