Skip to content

Frontend for GoModFix#532

Open
TylerMetz wants to merge 42 commits intoGoModFixfrom
GMF-ReconnectFrontend
Open

Frontend for GoModFix#532
TylerMetz wants to merge 42 commits intoGoModFixfrom
GMF-ReconnectFrontend

Conversation

@TylerMetz
Copy link
Owner

Describe your changes

After the backend changes we can optimize angular to work better with the routing changes

Issue ticket number and link

@TylerMetz
Copy link
Owner Author

I got it to the point where login is working, all my comments and things are still there if you want to go see what is going on, i think we should clean up the auth service post request next and then move too signup and then on from there @samforstot

@TylerMetz
Copy link
Owner Author

Also, i just uncommented the cookie in the backend and it is able to set it,
Screen Shot 2023-10-21 at 7 55 50 PM

@rileycleavenger rileycleavenger marked this pull request as ready for review October 22, 2023 00:28
@rileycleavenger rileycleavenger self-requested a review October 22, 2023 00:28
"net/http"

"github.com/gorilla/mux"
"github.com/rs/cors"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imported cors

router.HandleFunc("/UpdateRecipe", makeHTTPHandleFunc(s.handleUpdateRecipe))

http.ListenAndServe(s.listenAddr, router)
c := cors.New(cors.Options{
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap the whole routing middleware in cors handler, in allowedOrigins i think we have to add each route, ive only done login so thats all that is there

c := cors.New(cors.Options{
AllowedOrigins: []string{"http://localhost:4200", "http://localhost:4200/Login"}, // Add your frontend URLs
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"},
AllowedHeaders: []string{"*"},
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this just allows everything i think * = all ?


handler := c.Handler(router)

http.ListenAndServe(s.listenAddr, handler)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the handler here used to just be router, this adds the needed CORS stuff

Backend/api.go Outdated
Domain: "localhost",
}

// http.SetCookie(w, httpCookie)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im not sure if this would work? uncomment this, i thought it was breaking it

</div>
<div *ngIf="recipes && recipes.length > 0" class="recipe-instructions">
<div *ngIf="recipes[currentRecipeIndex].R.instructions" class="recipe-instructions">
<div *ngIf="recipes && recipes.RecipeToPost.length > 0" class="recipe-instructions">
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to match the recipe update

)
if err != nil {
fmt.Println("error on cookie post")
updateCookieerr := s.UpdateCookieByUserName(username, cookie)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a big thing giving me issues, if there is already a primary key in the database, meaning if a user has already had a cookie, then it cant insert and gives this error 'mssql: Violation of PRIMARY KEY constraint 'PK__user_coo__C9F284575894A090'. Cannot insert duplicate key in object 'dbo.user_cookies'. The duplicate key value is (json).'

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added error handling so that if this fails then it tries to update, then if that errs it fails

Domain: "localhost",
}

http.SetCookie(w, httpCookie)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this sets the cookie from our backend

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supa wild, we should probably implement a better hash system still?

logoutUrl: 'http://localhost:8080/Logout',
// Add more routes as needed
};

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interface for the routes to centralize them

public login(username: string, password: string): Observable<any> {
const body = { username, password };
return this.http.post(this.loginUrl, body, { observe: 'response', responseType: 'json', withCredentials: true });
public login(request: LoginRequest): Observable<any> {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

login is now clamped to a type of LoginRequest

{
    UserName: string,
    Password: string
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments