hn275 / envhub Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://envhub-rosy.vercel.app
License: GNU General Public License v3.0
Home Page: https://envhub-rosy.vercel.app
License: GNU General Public License v3.0
this can be done client side:
https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#search-repositories
/repos/link?id=123
id
is a repo id that can be used to request from github.Make an api call to github API to see if the user owns the repository or not, then delete it from the database if they are. I'm using Github ID's for both user and repository. The variables
column has the constraint to be deleted as well so no worries about cleaning up in that table.
I'm making an api calls to /repos/{repo-id}/delete
with a header entry for "Authorization" and cookie, but I have code to manage this data extraction, see below.
On success it should return a 204
with no response body on success. Otherwise a json
{"message":"some error"}
, with the appropriate status code.
http
package (ie: http.StatusNoContent
). In the interest of consistency, please use it as well, this will be the only micro-managing I do lol.1.1. Response
: To handle the communication to the frontend, they also provide some utilities for error handling.
1.2. RequestCtx
: To extract some useful information from the user. Note that this only works if you're are calling it from a handler that has the TokenValidator
middleware applied to it. Otherwise it returns an error, (which you may ignore, but leave a note indicating that it is being used in the appropriate route, I just find that it's less keystrokes for me to handle it since.. hotkeys...).
Response
struct.Could I have used an auth service? Maybe. But I wanted to learn how to implement this from scratch.
On user login, I'm rewriting to the database the user information, along with a refresh token, this is purely to update and sync the user information with GitHub, (nothing telemetry-like, I have more features in mind to utilize these information for the next version, if the app lasts).
User then receives an httpOnly
cookie that has the refresh token. This is only used to refresh the JWT, the access token is then ciphered and is contained within this JWT that exipires in 24h. These Github access token supposedly lasts for an entire year or after the first write request.
On sign out, the token in database is deleted, and the cookie will be invalidated. One issue is that we have no way to invalidate a JWT though...
The middleware TokenValidator
is applied to almost all of the routes, it validates the state of authorization and extract the needed access token for Github API call.
I've made a middleware to check for write access, this middleware should be applied for this endpoint as well.
This handler deletes a variable based on the request context being passed down by the middleware, take a look at the endpoint that creates a new variable (~ line 22, rCtx
).
No need to write test, I'll deal with that part. but you are expected to have the db function as an interface (see here.) This is so I can mock the testing bit of the db (test for the sql query will be written as well.)
NOTE:
response
api.NewResponse(w)...
server/handlers/router.go
, I'm making an api call from the front-end to repo/{repoID}/variables/{variableID}
, for both delete
and update
http methods. make sure to allow these when you are doing a request method check.A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.