Password protect the workers domain

Is it possible to setup a simple access protection for my workers domain?

It’s a simple page, and I don’t see a way in Workers docs to setup anything simillar to htaccess. Anyone did anything like that in the past?

Other than coding it into your worker, you can try Access. I was able to add an Access policy in front of my Workers site.

1 Like

What do you mean by coding it to my worker - are you talking about user authentication as a part of my website or smth workers related?

It’s my first worker based project, so I prefer to ask twice :slight_smile:

Definitely will look into the Access docs you mentioned. Thanks for sharing! :beers:

Include a Password Prompt in your script followed by a validation. Pass means the script continues, and fail exits the script.

Yeah, that’s a great idea. I have implemented it.
Are you aware how to access the Workers environment variables in my components in similar way to webpack’s process.env?

Not a clue. I’m not a coder, so I have to stumble my way through anything I do in Workers.

I was to fast to hit reply. It’s pretty easy actually - if you manage your your worker with the wrangler, just add the variable like this (leaving for future me’s):

  VARIABLE = 'value'

and you can than easily pick it up in your js, like any other env variable

const { VARIABLE } = process.env
1 Like