dleangen
08/06/2022, 3:51 AMdleangen
08/06/2022, 3:53 AMrp_st
08/06/2022, 4:24 AMdleangen
08/07/2022, 5:54 AMrp_st
08/07/2022, 5:55 AMdleangen
08/07/2022, 5:56 AMdleangen
08/07/2022, 6:00 AMdleangen
08/07/2022, 6:01 AMrp_st
08/07/2022, 6:08 AMdleangen
08/07/2022, 6:25 AMrp_st
08/07/2022, 6:29 AMdleangen
08/07/2022, 6:29 AMrp_st
08/07/2022, 6:30 AMrp_st
08/07/2022, 6:30 AMdleangen
08/07/2022, 6:30 AMdleangen
08/07/2022, 6:30 AMfalse
, even after authentication.
→ https://supertokens.com/docs/thirdpartyemailpassword/common-customizations/sessions/checking-session-front-end
I think that the init may not be correct.
Here are the FE logs:
init: called
init: Input apiBasePath: /auth
init: Input apiDomain: http://localhost:5001
init: Input autoAddCredentials: true
init: Input cookieDomain: undefined
init: Input isInIframe: false
init: Input sessionExpiredStatusCode: 401
init: Input sessionScope: localhost
doesSessionExist: called
getIdRefreshToken: called
getIdRefreshToken: is removed
doesSessionExist: called
getIdRefreshToken: called
getIdRefreshToken: is removed
dleangen
08/07/2022, 6:30 AMrp_st
08/07/2022, 6:31 AMrp_st
08/07/2022, 6:31 AMdleangen
08/07/2022, 6:32 AMdleangen
08/07/2022, 6:34 AMrp_st
08/07/2022, 7:40 AMdleangen
08/07/2022, 8:16 AMdleangen
08/07/2022, 8:16 AMdleangen
08/07/2022, 8:16 AMdleangen
08/07/2022, 8:17 AMdleangen
08/07/2022, 8:19 AMrp_st
08/07/2022, 8:29 AMrp_st
08/07/2022, 8:30 AMdleangen
08/07/2022, 8:47 AMdleangen
08/07/2022, 12:06 PMrp_st
08/07/2022, 1:15 PMrp_st
08/07/2022, 1:16 PMdleangen
08/07/2022, 1:51 PMInitialize the supertokens-web-js SDK in your angular app's root component. This will provide session management across your entire application.
The only change I made was for Angular 14 standalone components, which does not have a root component. I confirmed that the code is being called, but I don't seem to see the orange loading spinner...rp_st
08/07/2022, 1:52 PMrp_st
08/07/2022, 1:52 PMrp_st
08/07/2022, 1:52 PMrp_st
08/07/2022, 1:52 PMrp_st
08/07/2022, 1:53 PMdleangen
08/07/2022, 2:07 PMIn your auth component folder create a react component supertokensAuthComponent.tsx where we initialize the supertokens-auth-react SDK. This will tell SuperTokens which UI to show when the user visits the login page.
Here is the code: https://github.com/dleangen/supertokens-demo-1/blob/supertokens-ThirdPartyEmailPassword/src/app/components/signin/supertokens-auth.component.tsx#L7-L62
After that, I am trying to secure a route in the app, which is described here: https://supertokens.com/docs/thirdpartyemailpassword/common-customizations/sessions/securing-component
That page leads me here: https://supertokens.com/docs/thirdpartyemailpassword/common-customizations/sessions/checking-session-front-end
That asks me to do this:
import Session from 'supertokens-web-js/recipe/session';
async function doesSessionExist() {
if (await Session.doesSessionExist()) {
// user is logged in
} else {
// user has not logged in yet
}
}
But that requires the Supertokens.init from "supertokens-web-js". However, you are saying that I shouldn't be using that if I am using the prebuilt code.
I hope you see my circular problem...rp_st
08/07/2022, 2:25 PMrp_st
08/07/2022, 2:25 PMrp_st
08/07/2022, 2:27 PMrp_st
08/07/2022, 2:34 PMrp_st
08/07/2022, 3:14 PMrp_st
08/07/2022, 3:14 PMrp_st
08/07/2022, 3:14 PMrp_st
08/07/2022, 3:14 PMdleangen
08/07/2022, 3:15 PMrp_st
08/07/2022, 3:16 PMdleangen
08/07/2022, 3:17 PMrp_st
08/07/2022, 3:17 PMrp_st
08/07/2022, 3:17 PMrp_st
08/07/2022, 3:18 PMdleangen
08/07/2022, 3:19 PMrp_st
08/07/2022, 3:20 PMdleangen
08/07/2022, 3:20 PMdleangen
08/07/2022, 3:20 PMrp_st
08/07/2022, 3:21 PMrp_st
08/07/2022, 3:21 PMdleangen
08/07/2022, 3:21 PMrp_st
08/07/2022, 3:24 PMdleangen
08/11/2022, 6:04 AMrp_st
08/11/2022, 6:11 AMdleangen
08/11/2022, 6:58 AMrp_st
08/11/2022, 6:58 AMdleangen
08/11/2022, 7:04 AM{ path: 'auth', component: AuthComponent }
But actually, it requires something more like this:
{ path: 'auth', children: [ { path: '**', component: AuthComponent } ] }
I did not notice because I was using standalone components. I did not think it was relevant at the time. Turns out it is necessary. I only noticed when I updated the existing demo to use standalone components in Angular 14.dleangen
08/11/2022, 7:04 AMrp_st
08/11/2022, 7:04 AMdleangen
08/11/2022, 7:05 AMrp_st
08/11/2022, 7:07 AM**
(https://github.com/supertokens/supertokens-auth-react/blob/master/examples/with-angular-thirdpartyemailpassword/src/app/app-routing.module.ts#L6), and our demo app still works.dleangen
08/11/2022, 7:07 AMdleangen
08/11/2022, 7:07 AMrp_st
08/11/2022, 7:08 AMdleangen
08/11/2022, 7:08 AMdleangen
08/11/2022, 7:12 AM{
path: 'auth',
title: 'SuperTokens Demo – Sign In',
children: [
{
path: '**',
component: AuthComponent,
},
],
},
to this:
{
path: 'auth',
title: 'SuperTokens Demo – Sign In',
component: AuthComponent,
// children: [
// {
// path: '**',
// component: AuthComponent,
// },
// ],
},
it stops working.dleangen
08/11/2022, 7:15 AMrp_st
08/11/2022, 7:17 AM**
implicitly. Also, I would recommend using dynamic components since it won't include the supertokens-auth-react + react in the bundle for non auth routes -> reducing their bundle size by quite a bitdleangen
08/11/2022, 7:17 AMrp_st
08/11/2022, 7:18 AMdleangen
08/11/2022, 7:18 AMSuperTokens is an open source authentication solution offering features like: Different types of login: Email / password, Passwordless (OTP or Magic link based).
Powered by