# Tutorial: User Login and Registration in Ionic 4

**URL:** <https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075>\
**Category:** Developer Blog Comments\
**Created:** [June 19, 2019, 6:52pm UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075 "2019-06-19T18:52:49Z")\
**Posts on this page:** 20\
**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:** [June 19, 2019, 6:52pm UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/1 "2019-06-19T18:52:49Z")

</div>

[Tutorial: User Login and Registration in Ionic 4](https://developer.okta.com/blog/2019/06/20/ionic-4-tutorial-user-authentication-and-registration)

Ionic helps developers build hybrid mobile apps & PWAs. This tutorial shows you how to add user authentication and registration to an Ionic 4 app.

---

<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 3, 2019, 7:31am UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/2 "2019-08-03T07:31:33Z")

</div>

**Maurice Mugabo**

Thanks Matt, this is awesome guide. I like the way the whole integration is automated using the OktaDev Schematics, it really makes it pretty simple.  
I encountered 2 problems, one I was able to solve, the other I can’t:

1. I had to go in my okta dev account, API, Trusted Origins to enable CORS for localhost:8100 as the first time running ionic serve resulted in a cors issue.

2. Running in browser works perfect (ionic serve), but when I try to run my app in XCode emulator, I am getting to the login/sign up page, but after putting username/password, I get an error that “Safari can not open the page the address is invalid”. This is happening for both ios and android, I am afraid it might happen also once I put the updated app on my devices.

Has anyone else come across this issue as well? How to solve…

I am using this:

- macOS Mojave (version 10.14)  
- ionic 5.2.1 (was 4 but recently upgraded)  
- Angular CLI: 7.3.9  
- Node: 10.15.3  
- OS: darwin x64  
- Angular: 7.2.15  
- npm 6.4.1

I will put the app on a device in the next few hours and see what happens. Let me know what I can do about this issue.

Thanks.  
maurice-

---

<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 3, 2019, 4:15pm UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/3 "2019-08-03T16:15:47Z")

</div>

**Matt Raible**

Hello Maurice,

It sounds like you’re having issues redirecting back to your app after you login. This usually happens when your app’s custom scheme (e.g., [com.okta.dev](http://com.okta.dev "com.okta.dev")-123456) is not properly registered in your app, or doesn’t match what you have in Okta.

I’d make sure your app on Okta uses the same reversed domain as what’s registered in your package.json.

---

<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 4, 2019, 12:43pm UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/4 "2019-08-04T12:43:23Z")

</div>

**Maurice Mugabo**

Hi Matt, thanks a lot that was it…

But getting to the root cause was a little bit more involved… I tried another managed OAuth/IAM provider before Okta and in the process I added cordova-plugin-customurlscheme setting it to a totally different url\_scheme which was adding it to the configs every time I run the app… But that is fixed now had to remove the plugin and re-add.

Now my next wish list is this if you can point me to the Okta recommended way of doing things that would be great:

- Customizing those Okta login/register pages to look a bit more like my app  
- My API stack is NodeJs functions running behind AWS API Gateway - Lambda and access DynamoDB. Where is the guide to use API Gateway Custom Authorizers (or some other way) with Okta to verify those tokens and scopes and grant access to API resources.  
- Lastly, how do I parameterize this Okta configuration to have:   
 1. Different environments (Dev and QA or Staging, then eventually Production)   
 2. Is it done only thru the Admin UI, or we can have something more like serverless framework where you go and define it all out in a repeatable env configuration?

Thanks for your time…

---

<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 5, 2019, 7:01pm UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/5 "2019-08-05T19:01:52Z")

</div>

**Matt Raible**

For customizing the login page, you can check out [https://developer.okta.com](https://developer.okta.com "https://developer.okta.com"), scroll down, and play with customizing the sign-in widget. Or use [https://developer.okta.com/…](https://developer.okta.com/live-widget/ "https://developer.okta.com/live-widget/"). The gallery might be useful too:   
[https://developer.okta.com/…](https://developer.okta.com/login-widget-gallery/ "https://developer.okta.com/login-widget-gallery/")

A full guide is available at [https://developer.okta.com/…](https://developer.okta.com/code/javascript/okta_sign-in_widget/ "https://developer.okta.com/code/javascript/okta\_sign-in\_widget/").

I don’t know much about AWS so not sure how to do what you’re asking for there.

For different environments, you could create different accounts or different OIDC apps. All new developer accounts are created on our production tier.

Our API does allow you to create apps, users, etc., so you could probably automate creation/teardown if you wanted. Unfortunately, I don’t have examples of how to do this.

---

<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 6, 2019, 9:15am UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/6 "2019-08-06T09:15:02Z")

</div>

**Maurice Mugabo**

Thanks Matt, this helps a lot…

---

<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:** [September 13, 2019, 7:17pm UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/7 "2019-09-13T19:17:43Z")

</div>

**M Mercury**

This was a great article and was able to get the authentication running, I am running into a unique problem

When I deploy this app on the server( **non-ssl** ), the chrome browser gives me following error

Unable to generate PKCE challenge. Not using PKCE AppAuthError {message: “window.crypto.subtle is unavailable.”, extras: undefined}

My application works great in Safari and Firefox but fails in Chrome

Any suggestions would be greatly appreciated.

---

<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:** [September 13, 2019, 7:21pm UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/8 "2019-09-13T19:21:32Z")

</div>

**Matt Raible**

What version of Chrome and operating system are you using?

---

<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:** [September 16, 2019, 1:20pm UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/9 "2019-09-16T13:20:27Z")

</div>

**M Mercury**

I am using Chrome Version 77.0.3865.75(official Build) (64 bit) on Mac but tested this on Windows machines with latest Chrome browsers none of them 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:** [September 16, 2019, 1:24pm UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/10 "2019-09-16T13:24:29Z")

</div>

**Matt Raible**

According to [this Stack Overflow question](https://stackoverflow.com/questions/46670556/how-to-enable-crypto-subtle-for-unsecure-origins-in-chrome "https://stackoverflow.com/questions/46670556/how-to-enable-crypto-subtle-for-unsecure-origins-in-chrome"), `window.crypto` is only enabled on when you’re using localhost or HTTPS.

Can you please try enabling HTTPS on your server and see if the problem persists?

---

<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:** [September 18, 2019, 2:38am UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/11 "2019-09-18T02:38:29Z")

</div>

**M Mercury**

It appears that the CORS header is not being applied to the request. I tried adding the header in auth-http.service.ts but no luck. here is a configuratio. The get request fails with CORS and does not get response from https://\<\<companyid\>\>.okta.com/.well-known/openid-configuration and nothing happens.

please help.

private addHeaders(token) {  
 return (token) ? {  
 ‘Authorization’: `${token.tokenType} ${token.accessToken}`,  
 ‘Content-Type’: ‘application/json’,  
 ‘Access-Control-Allow-Origin’: ‘\*’  
 } : {};

---

<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:** [September 18, 2019, 3:04am UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/12 "2019-09-18T03:04:43Z")

</div>

**Okta Developers**

You need to configure Okta to allow [http://localhost:8100](http://localhost:8100) as a trusted origin. You can do this by logging in and going to API \> Trusted Origins.

---

<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:** [September 18, 2019, 11:30am UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/13 "2019-09-18T11:30:48Z")

</div>

**M Mercury**

Is adding trusted origin setting comes with custom authentication server? is this a paid feature?

---

<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:** [September 18, 2019, 2:52pm UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/14 "2019-09-18T14:52:26Z")

</div>

**M Mercury**

confirmed that the CORS and redirect settings are done correctly.

---

<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:** [September 20, 2019, 1:45am UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/15 "2019-09-20T01:45:34Z")

</div>

**Matt Raible**

No, adding trusted origins is not a paid feature. You can do it on a regular developer account. I believe it might be caused by Chrome 77, which does not allow 3rd party cookies by default. I’m not sure if it affects CORS too, but I did recently help someone that had CORS issues with Chrome. They tried Firefox and everything worked just fine.

---

<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 24, 2019, 4:59am UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/16 "2019-10-24T04:59:56Z")

</div>

**kuttimania\_2014 a**

Hi Matt,   
Thank you for writing this article.Just what I was looking for.  
how can handle the refresh token in ionic mobile app.

---

<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, 5:32pm UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/17 "2019-10-28T17:32:04Z")

</div>

**Matt Raible**

Hello,

This example uses [Ionic AppAuth](https://github.com/wi3land/ionic-appauth "https://github.com/wi3land/ionic-appauth"), which is built on [AppAuth-JS](https://github.com/openid/AppAuth-JS "https://github.com/openid/AppAuth-JS"). I believe refresh token support is included, but I haven’t tried it, so I’m not sure. You might try posting an issue in the Ionic AppAuth GitHub repo to see if they have an example.

---

<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:** [November 21, 2019, 3:09pm UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/18 "2019-11-21T15:09:15Z")

</div>

**Pritam Mullick**

Hi Matt,

Wonderful tutorial. So I followed entire of it and things are running well and good on the simulators. While when I build the Android and test it on a phone with Android 10, the app closes after the splash screen. Before integration of OKTA it was running well and good on all devices.   
Any idea, where I should look out for?

---

<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:** [November 21, 2019, 7:17pm UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/19 "2019-11-21T19:17:47Z")

</div>

**Matt Raible**

I’m not sure as I haven’t seen this behavior. You might be able to attach to your phone with Android Studio and see the logs. Unfortunately, I don’t have an Android phone to try and reproduce the problem with.

---

<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, 9:37am UTC](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075/20 "2019-12-24T09:37:11Z")

</div>

**kuttimania\_2014 a**

Thank you matt, It’s working

[Next page](https://devforum.okta.com/t/tutorial-user-login-and-registration-in-ionic-4/17075.md?page=2)
