This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function onSubmit({ username, password }) { | |
| return userService.login(username, password) | |
| .then((response) => { | |
| userService.setUserValue(response.data); | |
| router.push('/'); | |
| }) | |
| .catch(function(error){ | |
| console.log("ERROR HERE: "+error) | |
| setError('apiError', { message: "User Authentication failed" }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const userService = { | |
| userData: {}, | |
| register, | |
| login, | |
| }; | |
| function login(username, password) { | |
| return fetchWrapper.post(`/api/v1/login`, { username, password }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "log" | |
| "net/http" | |
| "github.com/joho/godotenv" | |
| "github.com/labstack/echo/v4" | |
| "github.com/pranotobudi/go-simple-ecommerce/api/products" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func (s *userHandler) CreateAccessToken() (string, error) { | |
| claims := jwt.StandardClaims{ | |
| ExpiresAt: time.Now().Add(time.Hour * 3).Unix(), | |
| IssuedAt: time.Now().Unix(), | |
| } | |
| token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) | |
| signedKey, err := token.SignedString([]byte(os.Getenv("JWT_SECRET_KEY"))) | |
| if err != nil { | |
| return signedKey, err |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func (h *userHandler) AuthUser(req UserLoginRequest) (*User, error) { | |
| username := req.Username | |
| password := req.Password | |
| fmt.Println("AUTHUSER CALLED, username: ", username, " password: ", password) | |
| //check Author Table | |
| user, err := h.repository.GetUserByUsername(username) | |
| if err != nil { | |
| return nil, fmt.Errorf("username is not registered") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func (h *userHandler) UserLogin(c echo.Context) error { | |
| // Input Binding | |
| userLogin := UserLoginRequest{} | |
| if err := c.Bind(&userLogin); err != nil { | |
| return api.ResponseErrorFormatter(c, err) | |
| } | |
| // Process Input | |
| authUser, err := h.AuthUser(userLogin) | |
| fmt.Println("We're IN HERE: USERLOGIN INSIDE: authUser: ", authUser) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type UserLoginRequest struct { | |
| Username string `json:"username"` | |
| Password string `json:"password"` | |
| } | |
| type UserLoginResponse struct { | |
| ID uint `json:"id"` | |
| Username string `json:"username"` | |
| Email string `json:"email"` | |
| AuthToken string `json:"auth_token"` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = { | |
| images: { | |
| domains: ["localhost", "fakestoreapi.com"] | |
| }, | |
| reactStrictMode: true, | |
| async rewrites() { | |
| return [ | |
| { | |
| source: '/api/v1/:path*', | |
| destination: 'http://localhost:8080/api/v1/:path*', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import getConfig from 'next/config'; | |
| import { userService } from 'pages/services/user.service'; | |
| const { publicRuntimeConfig } = getConfig(); | |
| export const fetchWrapper = { | |
| get, | |
| post, | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { BehaviorSubject } from 'rxjs'; | |
| import { fetchWrapper } from 'helpers/fetch-wrappers'; | |
| const userSubject = new BehaviorSubject(process.browser && JSON.parse(localStorage.getItem('user'))); | |
| export const userService = { | |
| user: userSubject.asObservable(), | |
| get userValue () { return userSubject.value }, | |
| register, |