DEV Community

Cover image for Authentication with Clerk in NestJS Server Application

Authentication with Clerk in NestJS Server Application

Oluwadamilola Babalola on January 04, 2025

Introduction This article provides a comprehensive, step-by-step guide to implementing authentication and authorization in a NestJS back...
Collapse
 
burkeholland profile image
Burke Holland

This post saved me. I have spent at least the last two evenings reading through all the docs trying to figure out how to use Clerk with a non-NextJS backend.

I cannot thank you enough. What is your patreon. :))

Collapse
 
thedammyking profile image
Oluwadamilola Babalola

I'm glad the post helped, you are welcome.
And I don't have a patreon account yet.

Collapse
 
jon_mccallum_463adcc6a9d5 profile image
Jon McCallum

Hey - just FYI. You can use the @clerk/express if you're running an express REST API - and then enable it in your AppModule in the middlewareConsumer. Much simpler

Collapse
 
davepaurillo profile image
DavePaurillo

Do you have any samples or working implementation of this?

Collapse
 
avvyyy profile image
Favour A. Uzochukwu

I would love to know what documentation you used to learn how to work on this. This was really helpful. I could only find docs for clerk + a frontend framework on the clerk website

Collapse
 
thedammyking profile image
Oluwadamilola Babalola

I got this by combing through Clerk and NestJS docs and trying different methods.

Collapse
 
davepaurillo profile image
DavePaurillo

Great documentation brother! Saved me tons of time. Did not know we can use passport with Clerk!

Collapse
 
thedammyking profile image
Oluwadamilola Babalola

You can most likely do that but you'd have to try that out yourself.

Collapse
 
austin_dady_c22313219b1de profile image
Austin Dady • Edited

Your clerk.strategy.ts on line 2 is:
import { Injectable, Injectable, UnauthorizedException } from '@nestjs/common';
but should be:
import { Injectable, Inject, UnauthorizedException } from '@nestjs/common';
Instead

Collapse
 
koodiklubi_testaa_1dc3a38 profile image
koodiklubi testaa

too many sweats, i'm passing on this spaghetti boilerplating

Collapse
 
thedammyking profile image
Oluwadamilola Babalola

It's just a guide and not meant to be a boilerplate.