File tree 8 files changed +123
-11
lines changed
server/WebApplication2/WebApplication2
8 files changed +123
-11
lines changed Original file line number Diff line number Diff line change 1
- # react-redux-saga-jwt-auth-aspnet
1
+ # Welcome to React Redux JWT Authentication using ASP.NET Core API !
2
+
3
+ ## Technology used
4
+
5
+ This repository uses a number of frameworks and libraries to work:
6
+
7
+ * [ ReactJS] - A JavaScript library for building user interfaces
8
+ * [ ASP.NET Core API] - Build secure REST APIs on any platform with C#
9
+ * [ SQL Server] - SQL Server 2019 Express is a free edition of SQL Server
10
+ * [ MongoDB] - The database for
11
+ modern applications
12
+
13
+
14
+ ## Installation and Run
15
+
16
+ Install the dependencies and devDependencies and start the server.
17
+
18
+ To run Auth server
19
+
20
+ ``` sh
21
+ $ cd .\s erver\A uthWebApplication\A uthWebApplication\
22
+ $ dotnet restore
23
+ $ dotnet run
24
+ ```
25
+ Verify the deployment by navigating to your server address in your preferred browser.
26
+
27
+ ``` sh
28
+ http://localhost:5000/
29
+ ```
30
+
31
+ To run Resource server
32
+
33
+ ``` sh
34
+ $ cd .\s erver\W ebApplication2\W ebApplication2
35
+ $ dotnet restore
36
+ $ dotnet watch run
37
+ ```
38
+ Verify the deployment by navigating to your server address in your preferred browser.
39
+
40
+ ``` sh
41
+ http://localhost:5005/
42
+ ```
43
+
44
+ To run client
45
+
46
+ ``` sh
47
+ $ cd .\c lient
48
+ $ npm install
49
+ $ npm start
50
+ ```
51
+ Verify the deployment by navigating to your server address in your preferred browser.
52
+
53
+ ``` sh
54
+ http://localhost:3000/
55
+ ```
56
+
57
+
58
+
59
+
60
+ ### Todos
61
+ - Write tests
62
+ - Add nodejs resource server
63
+
64
+ License
65
+ ----
66
+
67
+ MIT
68
+
69
+ [ node.js ] : < http://nodejs.org >
70
+ [ express ] : < http://expressjs.com >
71
+ [ ReactJS ] : < https://reactjs.org/ >
72
+ [ Gulp ] : < http://gulpjs.com >
73
+ [ ASP.NET Core API ] :< https://dotnet.microsoft.com/apps/aspnet/apis >
74
+ [ SQL Server ] :< https://www.microsoft.com/en-us/sql-server/sql-server-downloads >
75
+ [ MongoDB ] :< https://www.mongodb.com/ >
Original file line number Diff line number Diff line change @@ -26,7 +26,6 @@ export default (state = initialState, action) => {
26
26
} ;
27
27
default :
28
28
let localStorageData = localStorage . getItem ( 'data' ) ;
29
- console . log ( 'localStorageData' , localStorageData ) ;
30
29
if ( localStorageData ) {
31
30
localStorageData = JSON . parse ( localStorageData ) ;
32
31
return {
Original file line number Diff line number Diff line change 1
1
import axios from 'axios' ;
2
- // const BaseUrl = 'http://localhost:61361/api';
3
- const BaseUrl = 'http://feli-api.azurewebsites.net/api' ;
4
- const AuthUrl = 'http://localhost:5000'
2
+
3
+ const BaseUrl = 'http://localhost:5005/api' ;
4
+ const AuthUrl = 'http://localhost:5000' ;
5
+
6
+
7
+ axios . interceptors . request . use ( function ( config ) {
8
+ let localStorageData = localStorage . getItem ( 'data' ) ;
9
+ if ( localStorageData ) {
10
+ localStorageData = JSON . parse ( localStorageData ) ;
11
+ let token = 'Bearer ' + localStorageData . access_token ;
12
+ config . headers . Authorization = token ;
13
+ }
14
+ console . log ( config ) ;
15
+ return config ;
16
+ } ) ;
17
+
18
+
19
+ axios . interceptors . response . use ( function ( response ) {
20
+ return response ;
21
+ } , function ( error ) {
22
+ if ( error . response . status === 401 ) {
23
+ localStorage . removeItem ( 'data' ) ;
24
+ window . location = '/login' ;
25
+ } else {
26
+ return Promise . reject ( error ) ;
27
+ }
28
+ } ) ;
5
29
6
30
export const getPosts = ( ) => {
7
31
console . log ( "getPosts api call." ) ;
32
+ console . log ( axios . defaults ) ;
8
33
return axios . get ( `${ BaseUrl } /posts` ) ;
9
34
}
10
35
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ export function* addPost({ payload }) {
7
7
yield put ( { type : 'ADD_POST_SUCCESS' , payload : output } ) ;
8
8
yield put ( { type : 'FETCH_POSTS' } ) ;
9
9
} catch ( error ) {
10
- console . log ( 'fetch posts error' , error ) ;
10
+ console . log ( 'addPost error' , error ) ;
11
11
}
12
12
}
13
13
@@ -21,7 +21,7 @@ export function* editPost({ payload }) {
21
21
yield put ( { type : 'EDIT_POST_SUCCESS' , payload : output } ) ;
22
22
yield put ( { type : 'FETCH_POSTS' } ) ;
23
23
} catch ( error ) {
24
- console . log ( 'fetch posts error' , error ) ;
24
+ console . log ( 'editPost error' , error ) ;
25
25
}
26
26
}
27
27
@@ -35,7 +35,7 @@ export function* deletePost({ payload }) {
35
35
yield put ( { type : 'DELETE_POST_SUCCESS' , payload : output } ) ;
36
36
yield put ( { type : 'FETCH_POSTS' } ) ;
37
37
} catch ( error ) {
38
- console . log ( 'fetch posts error' , error ) ;
38
+ console . log ( 'deletePost error' , error ) ;
39
39
}
40
40
}
41
41
Original file line number Diff line number Diff line change 6
6
using Microsoft . AspNetCore . Mvc ;
7
7
using WebApplication2 . Models ;
8
8
using WebApplication2 . Services ;
9
+ using Microsoft . AspNetCore . Authorization ;
9
10
10
11
namespace WebApplication2 . Controllers
11
12
{
13
+ [ Authorize ]
12
14
[ Route ( "api/[controller]" ) ]
13
15
[ ApiController ]
14
16
public class CommentsController : ControllerBase
Original file line number Diff line number Diff line change 7
7
using Microsoft . AspNetCore . Mvc ;
8
8
using WebApplication2 . Models ;
9
9
using WebApplication2 . Services ;
10
+ using Microsoft . AspNetCore . Authorization ;
10
11
11
12
namespace WebApplication2 . Controllers
12
13
{
14
+ [ Authorize ]
13
15
[ EnableCors ( "all" ) ]
14
16
[ Route ( "api/[controller]" ) ]
15
17
[ ApiController ]
Original file line number Diff line number Diff line change 21
21
"commandName" : " Project" ,
22
22
"launchBrowser" : true ,
23
23
"launchUrl" : " weatherforecast" ,
24
- "applicationUrl" : " http://localhost:5000" ,
24
+ "applicationUrl" : " http://localhost:5005" ,
25
+ "environmentVariables" : {
26
+ "ASPNETCORE_ENVIRONMENT" : " Development"
27
+ }
28
+ },
29
+ "Watch" : {
30
+ "commandName" : " Watch" ,
31
+ "executablePath" : " C:\\ Program Files\\ dotnet\\ dotnet.exe" ,
32
+ "commandLineArgs" : " watch run" ,
33
+ "launchBrowser" : true ,
34
+ "launchUrl" : " http://localhost:5005" ,
25
35
"environmentVariables" : {
26
36
"ASPNETCORE_ENVIRONMENT" : " Development"
27
37
}
28
38
}
29
39
}
30
- }
40
+ }
Original file line number Diff line number Diff line change 1
1
{
2
2
"BookstoreDatabaseSettings" : {
3
3
"BooksCollectionName" : " Posts" ,
4
- "ConnectionString" : " mongodb+srv ://mongoadmin:Pa552123@cluster0-mz4lo.azure.mongodb.net /test" ,
4
+ "ConnectionString" : " mongodb://localhost:27017 /test" ,
5
5
"DatabaseName" : " node_boilerplate"
6
6
},
7
7
"Logging" : {
You can’t perform that action at this time.
0 commit comments