Skip to content

Commit

Permalink
🐛 Fix some bugs related to stytch for live / local test
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Apr 12, 2024
1 parent 361ad75 commit c04d74a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 19 deletions.
48 changes: 39 additions & 9 deletions apps/client-ts/src/components/Auth/b2c/LoginWithStytchSDKUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { StytchLogin } from '@stytch/nextjs';
import { StytchLoginConfig, OAuthProviders, Products, StyleConfig, StytchEvent, StytchError } from '@stytch/vanilla-js';
import { getDomainFromWindow } from '@/lib/stytch/urlUtils';
import { Button } from '@/components/ui/button';
import { Icons } from '@/components/shared/icons';

const sdkStyle: StyleConfig = {
fontFamily: '"Helvetica New", Helvetica, sans-serif',
Expand Down Expand Up @@ -31,18 +32,47 @@ const callbackConfig = {
onError: (error: StytchError) => console.log(error),
}

const getOauthUrl = (provider: string) => {
const isTest = process.env.NEXT_PUBLIC_STYTCH_PROJECT_ENV == 'test';
const baseStytch = isTest ? "test" : "api"
return `https://${baseStytch}.stytch.com/v1/public/oauth/${provider.toLowerCase()}/start?public_token=${process.env.NEXT_PUBLIC_STYTCH_PUBLIC_TOKEN}`;
}

const LoginWithStytchSDKUI = () => {
return (
<>
<div className='flex flex-row mb-2'>
<a href='https://test.stytch.com/v1/public/oauth/google/start?public_token=public-token-test-1881250c-afb6-4c09-b284-95592cf2fd62' target='_blank'>
<Button>Log In With Google</Button>
</a>
<a className='pl-3' href='https://test.stytch.com/v1/public/oauth/github/start?public_token=public-token-test-1881250c-afb6-4c09-b284-95592cf2fd62' target='_blank'>
<Button>Log In With Github</Button>
</a>
</div>
<StytchLogin config={sdkConfig} styles={sdkStyle} callbacks={callbackConfig} />
<div className='w-1'>
<StytchLogin config={sdkConfig} styles={sdkStyle} callbacks={callbackConfig} />
</div>
<div className="relative my-5">
<div className="absolute inset-0 flex items-center">
<span className="w-full border-t" />
</div>
<div className="relative flex justify-center text-xs uppercase">
<span className="bg-background px-2 text-muted-foreground">
Or continue with
</span>
</div>
</div>
<Button
variant={"outline"}
onClick={() => {
window.open(getOauthUrl("github"), '_blank');
}}
className='mb-2'
>
<Icons.gitHub className="mr-2 h-4 w-4" />{" "}
Github
</Button>
<Button
variant={"outline"}
onClick={() => {
window.open(getOauthUrl("google"), '_blank');
}}
>
<Icons.google className="mr-2 h-4 w-4" />{" "}
Google
</Button>
</>
)
}
Expand Down
26 changes: 26 additions & 0 deletions apps/client-ts/src/components/shared/icons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { LucideProps } from "lucide-react";



export const Icons = {
gitHub: ({ ...props }: LucideProps) => (
<svg
aria-hidden="true"
focusable="false"
data-prefix="fab"
data-icon="github"
role="img"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 496 512"
{...props}
>
<path
fill="currentColor"
d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3 .3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5 .3-6.2 2.3zm44.2-1.7c-2.9 .7-4.9 2.6-4.6 4.9 .3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3 .7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3 .3 2.9 2.3 3.9 1.6 1 3.6 .7 4.3-.7 .7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3 .7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3 .7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"
></path>
</svg>
),
google: ({ ...props }: LucideProps) => (
<svg {...props} xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" fill="#4285F4"/><path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853"/><path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" fill="#FBBC05"/><path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335"/><path d="M1 1h22v22H1z" fill="none"/></svg>
)
}
2 changes: 1 addition & 1 deletion packages/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ model connections {
expiration_timestamp DateTime? @db.Timestamp(6)
created_at DateTime @db.Timestamp(6)
connection_token String?
vertical String
id_project String @db.Uuid
id_linked_user String @db.Uuid
vertical String?
linked_users linked_users @relation(fields: [id_linked_user], references: [id_linked_user], onDelete: NoAction, onUpdate: NoAction, map: "fk_11")
projects projects @relation(fields: [id_project], references: [id_project], onDelete: NoAction, onUpdate: NoAction, map: "fk_9")
Expand Down
11 changes: 2 additions & 9 deletions packages/api/swagger/swagger-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,7 @@
],
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
"description": ""
}
},
"tags": [
Expand Down Expand Up @@ -665,7 +658,7 @@
"content": {
"application/json": {
"schema": {
"type": "object"
"type": "number"
}
}
}
Expand Down

0 comments on commit c04d74a

Please sign in to comment.