Westsi
Westsi

Reputation: 134

go - How can you serve static files with route based authorization with JWT in Gin?

I am trying to serve videos from a directory. I know how to do that (r.Static("/videos", "./videos")) but I have a directory for each user in there like /videos/testuser/video.mp4. I have implemented a login system with JWT, but how would I got about only letting testuser access /videos/testuser and user1 access /videos/user1?

Thanks!

Upvotes: 1

Views: 221

Answers (1)

Ray
Ray

Reputation: 320

Store the UserID in JWT and parse the JWT claims whenever someone downloads the video. Use fmt.Sprintf("videos/%s/video.mp4", jwt.UserId) to get the desired directory depends on different user.

Upvotes: 2

Related Questions