Is this possible with a plugin

I’m learning Lua from scratch, thinking about creating a plugin that works like this:

Use case 1:
A website or React app sends a request to kong with NO UserId in a header and NO JWT.
Kong sends the request on it’s way to the intended microservice (guest mode).

Use case 2:
A website or React app sends a request to kong with a UserId in a header.
If there are no JWT the plugin will redirect the request to a webpage which creates the JWT and redirects back to Kong, which in turn send the request on it’s way to the intended microservice which uses the JWT.

Use case 3:
A website or React app sends a request to kong with a UserId in a header AND a JWT.
Kong send the request on it’s way to the intended microservice which uses the JWT.

I hope I make some kind of sense.
Is this possible to do? Is it hard or easy? Are there already some solution to this out there? If not, I would greatly appreciate some general pointers to how I should go about doing this. I’ve been programming for some time but
never touched Lua ^^.

Thanks