Middleware Creation for GraphQL
Learn how to create a middleware for the GraphQL application.
We'll cover the following...
We'll cover the following...
Add a middleware
Before creating a middleware, we create some additional helpers in the auth.go file. These helpers verify the JWT token.
We add a helper function called ExtractTokenMetadata inside auth.go in the utils directory.
Function to extract the JWT token metadata
Below is an explanation of the code above:
-
In lines 13-16, the
TokenMetadatastruct is created to store the JWT token metadata. -
In line 21, the JWT token is verified.
-
In line 29, the claim of the JWT is extracted.
-
In line 32, the JWT token is validated.
-
In line 35, the JWT token is checked to ensure the token is valid.
-
In line 37, the JWT ...