(FIX): Auth seems to be working much better!
Finally, thank god. I still want a better way to manage the cookies. But not right now.
This commit is contained in:
parent
3177a4d089
commit
983d326a47
@ -39,7 +39,6 @@ func (s *Server) GoogleCallbackHandlerV2(ctx *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// BUG: This is not working, not yet sure why
|
||||
func (s *Server) LogoutHandlerV2(ctx *gin.Context) {
|
||||
s.SetCookie(ctx, "jwt_token", "", -1)
|
||||
// s.SetCookie(ctx, "search-filters", "", -1) // TODO: This was copied, might function differently now
|
||||
|
||||
@ -20,7 +20,7 @@ func (s *Server) SetCookie(ctx *gin.Context, name, value string, duration time.D
|
||||
path string = "/"
|
||||
httpOnly bool = false // NOTE: Should use false so React can see it!
|
||||
maxAge int
|
||||
secure bool = false
|
||||
secure bool = false
|
||||
domain string = ""
|
||||
)
|
||||
|
||||
|
||||
@ -5,9 +5,9 @@ import "time"
|
||||
// RecipeDuration is the duration to prepare recipe. It has JSON tags which allows it to be
|
||||
// marshaled into a JSON object and stored in the database (JSONB).
|
||||
type RecipeDuration struct {
|
||||
Total int `json:"total"`
|
||||
Prep int `json:"prep"`
|
||||
Cook int `json:"cook"`
|
||||
Total int `json:"Total"`
|
||||
Prep int `json:"Prep"`
|
||||
Cook int `json:"Cook"`
|
||||
}
|
||||
|
||||
// RecipeMeal is the database enum E_MEAL which defines the meal type of a recipe. Postgres enums
|
||||
@ -49,8 +49,8 @@ func ParseMeal(meal int) RecipeMeal {
|
||||
// RecipeIngredient is a single ingredients in a recipe. These have JSON tags which allow them
|
||||
// to be marshaled into a JSON array and stored in the database (JSONB).
|
||||
type RecipeIngredient struct {
|
||||
Name string `json:"name"`
|
||||
Quantity string `json:"quantity"`
|
||||
Name string `json:"Name"`
|
||||
Quantity string `json:"Quantity"`
|
||||
}
|
||||
|
||||
// Recipe is the database model of a recipe. There is no need to map to a different model so
|
||||
|
||||
@ -38,8 +38,8 @@ type InjectedDependencies struct {
|
||||
// JwtClaims is the data stored in the JSON web token. All that is needed is the users ID and their
|
||||
// Google email provided.
|
||||
type JwtClaims struct {
|
||||
UserId int `json:"id"`
|
||||
Email string `json:"email"`
|
||||
UserId int `json:"Id"`
|
||||
Email string `json:"Email"`
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
|
||||
|
||||
@ -4,13 +4,13 @@ import "time"
|
||||
|
||||
// GoogleUserInfo is a data type which contains a mapping of the Google User Info API call.
|
||||
type GoogleUserInfo struct {
|
||||
Id string `json:"id"`
|
||||
Email string `json:"email"`
|
||||
Verified bool `json:"verified_email"`
|
||||
Name string `json:"name"`
|
||||
GivenName string `json:"given_name"`
|
||||
FamilyName string `json:"family_name"`
|
||||
Picture string `json:"picture"`
|
||||
Id string `json:"Id"`
|
||||
Email string `json:"Email"`
|
||||
Verified bool `json:"VerifiedEmail"`
|
||||
Name string `json:"Name"`
|
||||
GivenName string `json:"GivenName"`
|
||||
FamilyName string `json:"FamilyName"`
|
||||
Picture string `json:"Picture"`
|
||||
}
|
||||
|
||||
// User is the database model of a user. There is no need to map to a different model so
|
||||
|
||||
@ -4,6 +4,10 @@ import './index.css'
|
||||
import App from './App.tsx'
|
||||
import { AuthProvider } from './context/AuthProvider.tsx'
|
||||
import { CookiesProvider } from 'react-cookie'
|
||||
import axios from "axios";
|
||||
|
||||
// Set the with 'withCredentials' by default
|
||||
axios.defaults.withCredentials = true;
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
|
||||
@ -3,7 +3,7 @@ import type { GetGoogleAuthUrlResponse, LogoutResponse } from "../types/api/auth
|
||||
import type { ApiError } from "../types/api/error";
|
||||
|
||||
|
||||
export async function GetGoogleAuthUrl (): Promise<string | ApiError> {
|
||||
export async function GetGoogleAuthUrl(): Promise<string | ApiError> {
|
||||
const response = await axios.get<GetGoogleAuthUrlResponse>("http://localhost:3000/v2/api/auth/login");
|
||||
|
||||
if (response.status !== 200) {
|
||||
@ -17,7 +17,7 @@ export async function GetGoogleAuthUrl (): Promise<string | ApiError> {
|
||||
return response.data.url;
|
||||
}
|
||||
|
||||
export async function Logout (): Promise<void> {
|
||||
export async function Logout(): Promise<void> {
|
||||
const response = await axios.get<LogoutResponse>("http://localhost:3000/v2/api/auth/logout");
|
||||
|
||||
// This should never happen
|
||||
|
||||
@ -5,7 +5,7 @@ import type { GetAuthenticateUserResponse } from "../types/api/user";
|
||||
|
||||
|
||||
export async function GetAuthenticatedUser(): Promise<User | ApiError> {
|
||||
const response = await axios.get<GetAuthenticateUserResponse>("http://localhost:3000/v2/api/user", { withCredentials: true });
|
||||
const response = await axios.get<GetAuthenticateUserResponse>("http://localhost:3000/v2/api/user");
|
||||
|
||||
if (response.data.status !== 200 || response.data.user === undefined){
|
||||
const err: ApiError = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user