Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passwordless example for angular #55

Open
wants to merge 7 commits into
base: 0.1
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: added environment configs
gitcommitshow committed Aug 12, 2022
commit 1e6e4f1d4262db013238e094f609b0fc4982b389
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<html>
<head>
<title>SuperTokens Passwordless Demo</title>
<title>{{ title }}</title>
<!--A no class CSS. Remove this if you want to add your own CSS.-->
<link rel="stylesheet" href="https://unpkg.com/sakura.css/css/sakura.css" />
</head>
<body>
<h2>SuperTokens Passwordless Demo</h2>
<h2>{{ title }}</h2>
<!-- This nav gives you links to click, which tells the router which route to use (defined in the routes constant in AppRoutingModule) -->
<nav>
<ul>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component } from '@angular/core';
import { environment } from '../environments/environment'

@Component({
selector: 'app-root',
@@ -7,5 +8,5 @@ import { Component } from '@angular/core';
})

export class AppComponent {
title = 'SuperTokens Passwordless Auth Demo - Angular';
title = environment.appName;
}
11 changes: 8 additions & 3 deletions examples/angular/with-passwordless/ui/src/app/auth.service.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import SuperTokens from 'supertokens-web-js';
import Session from 'supertokens-web-js/recipe/session';
import Passwordless from 'supertokens-web-js/recipe/passwordless';
import { environment } from '../environments/environment';

@Injectable({
providedIn: 'root'
@@ -15,9 +16,9 @@ export class AuthService {
configureAuth(){
SuperTokens.init({
appInfo: {
apiDomain: "http://localhost:3000",
apiBasePath: "/api",
appName: "SuperTokens-Passwordless-Demo",
apiDomain: environment.apiDomain,
apiBasePath: environment.apiBasePath,
appName: environment.appName,
},
recipeList: [
Session.init({
@@ -67,6 +68,10 @@ export class AuthService {
})
}

/**
* Call the backend API to email a unique code or magic link. Uses supertokens-web-js sdk function to do this.
* @param inputs { email?: string }
*/
sendCode(inputs: { email?: string }): Promise<string>{
if(!inputs || !inputs.hasOwnProperty("email")){
return Promise.reject("Invalid input. Please provide email.");
Original file line number Diff line number Diff line change
@@ -27,12 +27,12 @@ export class LoginComponent implements OnInit {
this.authService.sendCode(inputs).then((successText) => {
this.successText = successText;
this.errorText = "";
this.isCodeDelivered = true; // Show popup for login code when this is true
this.isCodeDelivered = true; // Show the input field to enter code now
}).catch((err) => {
// Set the error message
this.errorText = err;
this.successText = "";
this.isCodeDelivered = false;
this.isCodeDelivered = false; // Hide the input field to enter code now
})
}

Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@
// The list of file replacements can be found in `angular.json`.

export const environment = {
production: false
production: false,
apiDomain: "http://localhost:3000",
apiBasePath: "/api",
appName: "SuperTokens Passwordless Demo - Angular"
};

/*