Skip to content

Commit 6fdf75a

Browse files
committed
Add cors to auth service
1 parent 5e53741 commit 6fdf75a

File tree

6 files changed

+10
-5
lines changed

6 files changed

+10
-5
lines changed

authentication-service/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/cloudwego/base64x v0.1.4 // indirect
1616
github.com/cloudwego/iasm v0.2.0 // indirect
1717
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
18+
github.com/gin-contrib/cors v1.7.2 // indirect
1819
github.com/gin-contrib/sse v0.1.0 // indirect
1920
github.com/go-playground/locales v0.14.1 // indirect
2021
github.com/go-playground/universal-translator v0.18.1 // indirect

authentication-service/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
1111
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1212
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
1313
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
14+
github.com/gin-contrib/cors v1.7.2 h1:oLDHxdg8W/XDoN/8zamqk/Drgt4oVZDvaV0YmvVICQw=
15+
github.com/gin-contrib/cors v1.7.2/go.mod h1:SUJVARKgQ40dmrzgXEVxj2m7Ig1v1qIboQkPDTQ9t2E=
1416
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
1517
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
1618
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=

authentication-service/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"authentication-service/routes"
88
"authentication-service/services"
9+
"github.com/gin-contrib/cors"
910
"github.com/gin-gonic/gin"
1011
"github.com/joho/godotenv"
1112
)
@@ -19,6 +20,7 @@ func main() {
1920
defer services.DisconnectDB()
2021

2122
r := gin.Default()
23+
r.Use(cors.Default())
2224
routes.InitialiseRoutes(r)
2325
port := os.Getenv("PORT")
2426
if port == "" {

authentication-service/routes/routes.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
func InitialiseRoutes(r *gin.Engine) {
9-
r.POST("/register", controllers.RegisterUser)
10-
r.POST("/login", controllers.LoginUser)
11-
r.GET("/jwt", controllers.TokenLogin)
9+
r.POST("/api/v1/register", controllers.RegisterUser)
10+
r.POST("/api/v1/login", controllers.LoginUser)
11+
r.GET("/api/v1/jwt", controllers.TokenLogin)
1212
}

peerprep-fe/src/app/signin/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function LoginForm() {
1818
const handleLogin = async (e: React.FormEvent) => {
1919
e.preventDefault();
2020
setError('');
21-
const apiEndpoint = 'http://localhost:4040/login';
21+
const apiEndpoint = 'http://localhost:4040/api/v1/login';
2222
const result = await fetch(apiEndpoint, {
2323
method: 'POST',
2424
headers: {

peerprep-fe/src/app/signup/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function SignUpPage() {
2020
const handleSignUp = async (e: React.FormEvent) => {
2121
e.preventDefault();
2222
setError('');
23-
const apiEndpoint = 'http://localhost:4040/register';
23+
const apiEndpoint = 'http://localhost:4040/api/v1/register';
2424
const type = 'user';
2525
const result = await fetch(apiEndpoint, {
2626
method: 'POST',

0 commit comments

Comments
 (0)