Skip to content

redirectToSignIn not respecting publishableKey passed to authMiddleware #1442

Closed
@dcyoung

Description

@dcyoung

I'm using a custom env var naming scheme in order to provide env vars at deploy time.
I am able to supply the publishableKey as a parameter to the middleware,

export default authMiddleware({
    publishableKey: process.env.ENV_VAR_NAME,
    async afterAuth(auth, req, evt) {
        if (!auth.isPublicRoute ) {
            if (!auth.userId) {
                // eslint-disable-next-line @typescript-eslint/no-unsafe-return
                return redirectToSignIn({

but when I call redirectToSignIn within afterAuth, I am getting an error:

Server Error
Error: Missing publishableKey. You can get your key at https://dashboard.clerk.com/last-active?path=api-keys.

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Source
src/middleware.ts (45:40) @ afterAuth

  44 | // eslint-disable-next-line @typescript-eslint/no-unsafe-return
> 45 | return redirectToSignIn({
     |                        ^
  46 |     returnBackUrl: ...,
  48 | });

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnextjsprioritizedThis issue has been triaged and the team is working on it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions