# Simple User Authentication in React

**URL:** <https://devforum.okta.com/t/simple-user-authentication-in-react/17015>\
**Category:** Developer Blog Comments\
**Created:** [March 18, 2019, 9:51pm UTC](https://devforum.okta.com/t/simple-user-authentication-in-react/17015 "2019-03-18T21:51:50Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [March 18, 2019, 9:51pm UTC](https://devforum.okta.com/t/simple-user-authentication-in-react/17015/1 "2019-03-18T21:51:50Z")

</div>

[Simple User Authentication in React](https://developer.okta.com/blog/2019/03/18/beginners-guide-to-redux)

Learn the basics of Redux for React.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [June 26, 2019, 7:18pm UTC](https://devforum.okta.com/t/simple-user-authentication-in-react/17015/2 "2019-06-26T19:18:17Z")

</div>

**Brian**

Is there any way to access the auth object outside of a React component? It seems like an anti-pattern to pass it into every React component that needs to make an api call.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [July 9, 2019, 9:21pm UTC](https://devforum.okta.com/t/simple-user-authentication-in-react/17015/3 "2019-07-09T21:21:30Z")

</div>

**Matt Raible**

Hello Brian,

For this case, you can create the Auth object outside of React and pass it to the `Security` component on its props: [https://github.com/okta/okt…](https://github.com/okta/okta-oidc-js/blob/master/packages/okta-react/src/Security.js#L21 "https://github.com/okta/okta-oidc-js/blob/master/packages/okta-react/src/Security.js#L21")

```
this.auth = props.auth || new Auth(props);
```

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [October 26, 2019, 5:51am UTC](https://devforum.okta.com/t/simple-user-authentication-in-react/17015/4 "2019-10-26T05:51:32Z")

</div>

**Daniel Kennedy**

This works well on localhost, but on the deployed version (Netlify) I get a 404 for /implicit/callback. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [October 26, 2019, 7:00am UTC](https://devforum.okta.com/t/simple-user-authentication-in-react/17015/5 "2019-10-26T07:00:25Z")

</div>

**Daniel Kennedy**

OK, I worked it out: [https://www.slightedgecoder…](https://www.slightedgecoder.com/2018/12/18/page-not-found-on-netlify-with-react-router/ "https://www.slightedgecoder.com/2018/12/18/page-not-found-on-netlify-with-react-router/")

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [October 28, 2019, 4:58pm UTC](https://devforum.okta.com/t/simple-user-authentication-in-react/17015/6 "2019-10-28T16:58:19Z")

</div>

**Matt Raible**

Thanks for letting us know! Glad you figured it out. 🙂

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [December 24, 2019, 7:18pm UTC](https://devforum.okta.com/t/simple-user-authentication-in-react/17015/7 "2019-12-24T19:18:55Z")

</div>

**Cicero Wolowski**

Hi,

well I’m stuck with my SPA and hashed urls ☹ I cant make this work

I have my react application that uses hash based url’s ([http://localhost:8080/#/login](http://localhost:8080/#/login)), on my SPA app I have “  
[http://localhost:8080/implicit/callback](http://localhost:8080/implicit/callback)” as my callback url. My routes configuration has , so everything in place.

But after provide my credentials (user/pass) on the okta-signin-widget, I have “[http://localhost:8080/implicit/callback#/code=rCZxRR9mQ8\_VTQHyCMLU&state=fTvGLGXqjx1QenupaZy5dBHzrUbYxjs4DCn6jvYHkIfualK01TqVW”](http://localhost:8080/implicit/callback#/code=rCZxRR9mQ8_VTQHyCMLU&state=fTvGLGXqjx1QenupaZy5dBHzrUbYxjs4DCn6jvYHkIfualK01TqVW%E2%80%9D) as result of the redirect from OKTA, but this results in a not found, probably because of the hash based url.

I have been walking in circles with this issue, can somebody help-me with ideas on how to solve this?

Thanks,

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [December 24, 2019, 8:14pm UTC](https://devforum.okta.com/t/simple-user-authentication-in-react/17015/8 "2019-12-24T20:14:21Z")

</div>

**Matt Raible**

The OAuth spec requires that only one hash fragment exist. See the following issue for possible workarounds.   
[https://github.com/okta/okt…](https://github.com/okta/okta-oidc-js/issues/29#issuecomment-342339960 "https://github.com/okta/okta-oidc-js/issues/29#issuecomment-342339960")

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [January 12, 2020, 12:49am UTC](https://devforum.okta.com/t/simple-user-authentication-in-react/17015/9 "2020-01-12T00:49:59Z")

</div>

**Raymond Pugh Jr.**

How would you go about connecting the log in to a deployed backend? I can’t seem to modify

` login() { let port = (window.location.port ? ‘:’ + window.location.port : ‘’); if (port === ‘:3000’) { port = ‘:8080’; } window.location.href = ‘//’ + window.location.hostname + port + ‘/private’; }` in any way that will work.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [January 15, 2020, 6:11pm UTC](https://devforum.okta.com/t/simple-user-authentication-in-react/17015/10 "2020-01-15T18:11:03Z")

</div>

**Matt Raible**

I don’t see any reference to “/private” in this post. Another [React post I wrote has it](https://developer.okta.com/blog/2018/07/19/simple-crud-react-and-spring-boot "https://developer.okta.com/blog/2018/07/19/simple-crud-react-and-spring-boot"). Did you mean to post this comment there?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 19, 2020, 7:40pm UTC](https://devforum.okta.com/t/simple-user-authentication-in-react/17015/11 "2020-08-19T19:40:40Z")

</div>

**Barnett**

I was hopeful that this tutorial would be beginner friendly. Alas, it is not.

For example:  
1) “withAuth” throws a type error and Okta’s docs currently say to use "withOktaAuth"  
2) Abstracting to auth.js doesn’t work per the above as auth is undefined

☹ Hopefully Firebase is more beginner friendly

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 19, 2020, 7:45pm UTC](https://devforum.okta.com/t/simple-user-authentication-in-react/17015/12 "2020-08-19T19:45:37Z")

</div>

**Matt Raible**

Hello Barnett. If you use `@okta/okta-react v1.2.0` as specified in this tutorial, everything should work as expected. 🙂

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [February 13, 2021, 10:52am UTC](https://devforum.okta.com/t/simple-user-authentication-in-react/17015/13 "2021-02-13T10:52:54Z")

</div>

**munawar**

Hi when i tried to integrate widget in react webpack app, i am getting following error. please help me out

./node\_modules/@okta/okta-signin-widget/dist/img/icons/mfa/u2f\_70x70.png 1:0  
Module parse failed: Unexpected character ‘�’ (1:0)  
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See [https://webpack.js.org/conc…](https://webpack.js.org/concepts#loaders "https://webpack.js.org/concepts#loaders")  
(Source code omitted for this binary file)

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [June 7, 2021, 10:03am UTC](https://devforum.okta.com/t/simple-user-authentication-in-react/17015/14 "2021-06-07T10:03:42Z")

</div>

**adi**

i’m having an error in Login.js ,it says that status is undefined

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [June 7, 2021, 5:21pm UTC](https://devforum.okta.com/t/simple-user-authentication-in-react/17015/15 "2021-06-07T17:21:20Z")

</div>

**Matt Raible**

If you’re using the same library versions that are used in this post, everything should work. If you’re still having issued, I’d recommend using the [updated tutorial referenced at the top of this one](https://developer.okta.com/blog/2020/12/16/react-login "https://developer.okta.com/blog/2020/12/16/react-login").
