GithubHelp home page GithubHelp logo

backend-engineering-octernship's Issues

Unable to store cookies: http.Cookies are getting stored in postman but not in browser

On User 's successful login request ,I am saving tokens as http.cookies from the backend.
When i make login request using postman the cookies are stored in postman's cookies but on the other hand if i make login request through my React.js client from browser they are not stored in browser's cookies section. i.e.(/devtools/application/cookies)

Code:

Storing cookie-

ctx.SetCookie("accesstoken", token, int(AppConstant.TOKEN_COOKIE_EXPIRY), "/", "localhost", false, true)
ctx.SetCookie("refreshtoken", refreshedToken, int(AppConstant.REFRESH_TOKEN_COOKIE_EXPIRY), "/", "localhost", false, true)

Login request from react.js client-

export async function AuthenticateUser  (username,password) {
        const res=await fetch(API_URL+API_LOGIN_ENDPOINT,{
        method:"POST",
        headers:{
            'Accept': 'application/json',   
            "Content-Type":"application/json"
        },
        
        mode:"cors",
        body:JSON.stringify({
            "username":username,
            "password":password,
        }),

    });
    return res.status===200

}

Frameworks used: Gin-Gonic(Backend) ,React.js(Frontend)
Tested on Browsers:Firefox ,brave.

Although i have read and tried some threads on internet that latest browser ignores domain="localhost" and also domain containing less than 2 periods i.e. "api.app.localhost" is valid but "localhost" is not.
One thing i could do is, get tokens from backend and then save them in cookies at client side and then further use them
but that's not good practice as per many people.
Then how can i achieve my goal of storing cookies in browser when domain is localhost ,In order to setup test environment for this assignment ?

How to submit assignment properly ?

In assignment-update's branch readme file ,it is written that submission should on github classroom,but i am unable to find any classroom related to houseware.
While in feedback branch's readme file it is written that we have to make changes on feedback branch and not merge auto-generated PR on feedback from main.
I have done changes on feedback branch but meanwhile by mistake i have merged the auto-generated PR on feedback from main. What should i do ?
And do i have to commit final changes on main or feedback branch?

What is the best practice to revoke token?

Assume a case in our assignment,that a ADMIN removes itself from database.
Now the logic i have wrote,allows this removed ADMIN to access authorised endpoints until access-token expires(happens after 1hr)
and then after 1 hr during refresh token rotation it throws 401:Unauthorised as user doesnt not exist anymore.

I want to know what is the best practice to revoke a token and shutdown user's authorised access?
Is it okay to just stick with the logic i have or there can be something more effective for this assignment purpose.

EDIT:Implemented logic which checks whether user exists in DB or not while validating access-token in authorization middleware.Basically using token's claims ,user's document ID will be provided from token to .findByID() method to query in database if this fails then user no longer exists hence user is now unauthorised

What logic to add for unit testing API endpoints ?

'Note: Do add unit tests(for success & failure) for each API endpoint.' as mentioned in README.md file.
I am trying to add unit tests but i am not understanding what logic should i add for testing endpoints.
For eg
/login -> how can i unit test this endpoint?

Please someone help.

Submitting Changes

Am I supposed to fork the project and work on the main branch of the fork and push the changes to the main branch and wait for it to be reviewed?

I'm a little bit confused.

Cannot import modules.

I'm trying to import modules but I keep getting same error message: "no required module provides package XYZ"
I'm so tired spending hours on trying to figure this out. I ran "go mod init" but no luck.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.