DEV Community

Aryan Dwivedi
Aryan Dwivedi

Posted on

Wanted to access url based on user role in my app but there seems to be some problem

i have addedd authorization token in react and ROLE_ADMIN is role stored in database
you cxan review my code at github

https://github.com/RND2002/quizSpringboot
https://github.com/RND2002/quizReact
Please help me to complete this my deadline is nere

You can review my code at ->https://github.com/RND2002/quizSpringboot

you can review my react code at->https://github.com/RND2002/quizReact

//error in react console

AuthContext.js:32 intercepting and adding a token
createQuiz:1 Access to XMLHttpRequest at 'http://localhost:8080/quiz/create?category=a&num=1&title=hndth' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
QuestionCreation.jsx:40 AxiosError {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …}
xhr.js:256

   POST http://localhost:8080/quiz/create?category=a&num=1&title=hndth net::ERR_FAILED
Enter fullscreen mode Exit fullscreen mode

//error in sprinig boot log
Authenticated user
2023-10-27T20:25:20.725+05:30 DEBUG 4812 --- [nio-8080-exec-1] o.s.s.w.a.www.BasicAuthenticationFilter : Set SecurityContextHolder to UsernamePasswordAuthenticationToken [Principal=org.springframework.security.core.userdetails.User [Username=ranga2, Password=[PROTECTED], Enabled=true, AccountNonExpired=true, credentialsNonExpired=true, AccountNonLocked=true, Granted Authorities=[ROLE_ADMIN]], Credentials=[PROTECTED], Authenticated=true, Details=WebAuthenticationDetails [RemoteIpAddress=0:0:0:0:0:0:0:1, SessionId=null], Granted Authorities=[ROLE_ADMIN]]
2023-10-27T20:25:20.745+05:30 DEBUG 4812 --- [nio-8080-exec-1] o.s.security.web.FilterChainProxy : Secured GET /basicauth
2023-10-27T20:25:39.848+05:30 DEBUG 4812 --- [nio-8080-exec-2] o.s.security.web.FilterChainProxy : Securing OPTIONS /quiz/create?category=a&num=1&title=hndth
2023-10-27T20:25:39.849+05:30 DEBUG 4812 --- [nio-8080-exec-2] o.s.s.w.a.AnonymousAuthenticationFilter : Set SecurityContextHolder to anonymous SecurityContext
2023-10-27T20:25:39.853+05:30 DEBUG 4812 --- [nio-8080-exec-2] s.w.a.DelegatingAuthenticationEntryPoint : Trying to match using RequestHeaderRequestMatcher [expectedHeaderName=X-Requested-With, expectedHeaderValue=XMLHttpRequest]
2023-10-27T20:25:39.854+05:30 DEBUG 4812 --- [nio-8080-exec-2] s.w.a.DelegatingAuthenticationEntryPoint : No match found. Using default entry point org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint@3c0dea36
2023-10-27T20:25:39.860+05:30 DEBUG 4812 --- [nio-8080-exec-2] o.s.security.web.FilterChainProxy : Securing OPTIONS /error?category=a&num=1&title=hndth
2023-10-27T20:25:39.865+05:30 DEBUG 4812 --- [nio-8080-exec-2] o.s.s.w.a.AnonymousAuthenticationFilter : Set SecurityContextHolder to anonymous SecurityContext
2023-10-27T20:25:39.865+05:30 DEBUG 4812 --- [nio-8080-exec-2] s.w.a.DelegatingAuthenticationEntryPoint : Trying to match using RequestHeaderRequestMatcher [expectedHeaderName=X-Requested-With, expectedHeaderValue=XMLHttpRequest]
2023-10-27T20:25:39.866+05:30 DEBUG 4812 --- [nio-8080-exec-2] s.w.a.DelegatingAuthen****

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay