Hi I'm trying to setup nestjs and fastify with sup...
# support-questions-legacy
h
Hi I'm trying to setup nestjs and fastify with supertokens. Following the guide on the website I get to the guard.
Copy code
ts
import { CanActivate, ExecutionContext, Injectable } from "@nestjs/common"
import { Error as STError } from "supertokens-node"

import { VerifySessionOptions } from "supertokens-node/recipe/session"
import { verifySession } from "supertokens-node/recipe/session/framework/express"

@Injectable()
export class AuthGuard implements CanActivate {
  constructor(private readonly verifyOptions?: VerifySessionOptions) {}

  async canActivate(context: ExecutionContext): Promise<boolean> {
    const ctx = context.switchToHttp()

    let err = undefined
    const resp = ctx.getResponse()
    // You can create an optional version of this by passing {sessionRequired: false} to verifySession
    await verifySession(this.verifyOptions)(ctx.getRequest(), resp, (res) => {
      err = res
    })

    if (resp.headersSent) {
      throw new STError({
        message: "RESPONSE_SENT",
        type: "RESPONSE_SENT",
      })
    }

    if (err) {
      throw err
    }

    return true
  }
}
Which is the snippet from the docs, how can I modify this to work with fastify?
18 Views