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

feature(unlock-app): Wallet-only auth for embedded paywall #15379

Merged
merged 4 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 11 additions & 1 deletion unlock-app/src/config/PrivyProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ToastHelper } from '~/components/helpers/toast.helper'
import { locksmith } from './locksmith'
import AuthenticationContext from '~/contexts/AuthenticationContext'
import { MigrationModal } from '~/components/legacy-auth/MigrationNotificationModal'
import { isInIframe } from '~/utils/iframe'

// check for legacy account
export const checkLegacyAccount = async (
Expand Down Expand Up @@ -188,13 +189,22 @@ export const Privy = ({ children }: { children: ReactNode }) => {
typeof window !== 'undefined' &&
window.location.pathname.includes('migrate-user')

// Check if we're in an iframe && not in the Unlock dashboard
const isInPaywall =
isInIframe() && !window.location.href.includes(config.unlockApp)

return (
<AuthenticationContext.Provider value={{ account, setAccount }}>
<PrivyProvider
config={{
/* For the meantime, when users are authenticating via paywall on an external website (embedded paywall),
* we can only allow the wallet method to login.
*/
loginMethods: isMigratePage
? ['email']
: ['wallet', 'email', 'google', 'farcaster'],
: isInPaywall
? ['wallet']
: ['wallet', 'email', 'google', 'farcaster'],
embeddedWallets: {
createOnLogin: 'off',
},
Expand Down
1 change: 1 addition & 0 deletions unlock-app/src/utils/iframe.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const isInIframe = () => {
if (typeof window === 'undefined') return false
return window !== window.parent || window.top !== window
}
Loading