Skip to content

Instantly share code, notes, and snippets.

@fl0wo
Created December 12, 2022 17:31
Show Gist options
  • Save fl0wo/8c890cb9cacd6ab5b16c2cdaec67d298 to your computer and use it in GitHub Desktop.
Save fl0wo/8c890cb9cacd6ab5b16c2cdaec67d298 to your computer and use it in GitHub Desktop.
Stytch component js used to inject UI on div
import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core';
import {environment} from "../../environments/environment";
import {stytchUIClient} from "../../environments/stytchClient";
import {OAuthProviders, Products, StytchUIClient} from "@stytch/vanilla-js";
import {OneTapPositions, StyleConfig, StytchLoginConfig} from "@stytch/core/public";
@Component({
selector: 'app-stytch-join',
templateUrl: './stytch-join.component.html',
styleUrls: ['./stytch-join.component.scss']
})
export class StytchJoinComponent implements OnInit,AfterViewInit {
@ViewChild('magic_stytch_login')
divLogin:any;
loginPanelWidth: number=390;
constructor() {}
ngOnInit(): void {}
ngAfterViewInit(): void {
this.renderStytchUIClient();
}
private renderStytchUIClient() {
if(!!stytchUIClient){
this.mountStitchUI(stytchUIClient);
}
}
private mountStitchUI(s:StytchUIClient) {
const x = this.divLogin.nativeElement.id;
const config:StytchLoginConfig = {
products: [
Products.oauth
],
oauthOptions:{
providers:[
{
type: OAuthProviders.Google,
one_tap:true,
position:OneTapPositions.embedded
}
],
loginRedirectURL: environment.REDIRECT_LOGIN_OAUTH,
signupRedirectURL: environment.REDIRECT_SIGNIN_OAUTH
}
}
const styles:StyleConfig = {
container: {
backgroundColor: "transparent",
borderColor: "transparent",
borderRadius: "0px",
width: this.loginPanelWidth + "px"
},
colors: {
primary: "#19303D",
secondary: "#5C727D",
success: "#0C5A56",
error: "#8B1214"
},
buttons: {
primary: {
backgroundColor: "#19303D",
textColor: "#FFFFFF",
borderColor: "#19303D",
borderRadius: "4px"
},
secondary: {
backgroundColor: "#FFFFFF",
textColor: "#19303D",
borderColor: "#19303D",
borderRadius: "4px"
}
},
fontFamily: "Arial",
hideHeaderText: true
}
s.mountLogin({
elementId: '#'+x,
config:config,
styles:styles
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment