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

[PROTO-1787] Add full screen oauth variant #8233

Merged
merged 3 commits into from
Apr 25, 2024
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
2 changes: 2 additions & 0 deletions docs/docs/developers/guides/log-in-with-audius.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ You must open this page with the required URL parameters, described below.
whether the auth flow response parameters will be encoded in the query string or the fragment
component of the redirect_uri when redirecting back to your app. Default behavior is equivalent to
"fragment". We recommend NOT changing this if possible.
- `display` _optional_ `"popup" | "fullScreen"` - determines whether the auth flow expects to be
rendered in a popup or a full screen view. Defaulted to `"popup"` if unspecified.

**Example**

Expand Down
3 changes: 2 additions & 1 deletion packages/ddex/webapp/client/src/pages/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const Login = () => {
if (audiusSdk && auto) {
audiusSdk.oauth!.login({
scope: 'write',
redirectUri: new URL(window.location.href).origin
redirectUri: new URL(window.location.href).origin,
display: 'fullScreen'
})
}
}, [audiusSdk, auto])
Expand Down
7 changes: 5 additions & 2 deletions packages/libs/src/sdk/oauth/OAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ export class OAuth {
login({
scope = 'read',
params,
redirectUri = 'postMessage'
redirectUri = 'postMessage',
display = 'popup'
}: {
scope?: OAuthScope
params?: WriteOnceParams
redirectUri?: string
display?: 'popup' | 'fullScreen'
}) {
const scopeFormatted = typeof scope === 'string' ? [scope] : scope
if (!this.config.appName && !this.apiKey) {
Expand Down Expand Up @@ -249,7 +251,8 @@ export class OAuth {

const fullOauthUrl = `${
OAUTH_URL[this.env]
}?scope=${effectiveScope}&state=${csrfToken}&redirect_uri=${redirectUri}&origin=${originURISafe}&${appIdURIParam}${writeOnceParams}`
}?scope=${effectiveScope}&state=${csrfToken}&redirect_uri=${redirectUri}&origin=${originURISafe}&${appIdURIParam}${writeOnceParams}&display=${display}`

if (redirectUri === 'postMessage') {
this.activePopupWindow = window.open(fullOauthUrl, '', windowOptions)
this._clearPopupCheckInterval()
Expand Down
18 changes: 11 additions & 7 deletions packages/web/src/pages/oauth-login-page/OAuthLoginPage.module.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
.bgWhite {
background-color: var(--harmony-static-white);
}

.wrapper {
margin: 0 auto;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
justify-content: center;
width: 375px;
display: flex;
overflow: scroll;
}

.popup {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use --harmony-bg-white, so that it's not stuck on white if the user is in dark mode?
Only matters if the rest of this supports themes though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

og design had it static white, so i kept as is!

background-color: var(--harmony-static-white);
}

.centeredContent {
Expand All @@ -29,7 +33,7 @@
text-overflow: ellipsis;
}

.loadingStateContainer {
.popup .loadingStateContainer {
margin-top: 200px;
}

Expand Down
17 changes: 6 additions & 11 deletions packages/web/src/pages/oauth-login-page/OAuthLoginPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FormEvent, useLayoutEffect, useState } from 'react'
import { FormEvent, useState } from 'react'

import { Name, ErrorLevel } from '@audius/common/models'
import { accountSelectors, signOutActions } from '@audius/common/store'
Expand Down Expand Up @@ -35,12 +35,6 @@ const { signOut } = signOutActions
const { getAccountUser } = accountSelectors

export const OAuthLoginPage = () => {
useLayoutEffect(() => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handled in css

document.body.classList.add(styles.bgWhite)
return () => {
document.body.classList.remove(styles.bgWhite)
}
}, [])
const record = useRecord()
const account = useSelector(getAccountUser)
const isLoggedIn = Boolean(account)
Expand Down Expand Up @@ -156,7 +150,8 @@ export const OAuthLoginPage = () => {
appImage,
userEmail,
authorize,
txParams
txParams,
display
} = useOAuthSetup({
onError: handleAuthError,
onPendingTransactionApproval: handlePendingTransactionApproval,
Expand Down Expand Up @@ -247,7 +242,7 @@ export const OAuthLoginPage = () => {

if (queryParamsError) {
return (
<ContentWrapper>
<ContentWrapper display={display}>
<div className={cn(styles.centeredContent, styles.titleContainer)}>
<span className={styles.errorText}>{queryParamsError}</span>
</div>
Expand All @@ -256,7 +251,7 @@ export const OAuthLoginPage = () => {
}
if (loading) {
return (
<ContentWrapper>
<ContentWrapper display={display}>
<div
className={cn(styles.centeredContent, styles.loadingStateContainer)}
>
Expand All @@ -271,7 +266,7 @@ export const OAuthLoginPage = () => {
}

return (
<ContentWrapper>
<ContentWrapper display={display}>
<Flex alignItems='center' direction='column'>
<Flex gap='l' alignItems='center' mb='l'>
<Flex h='88px' w='88px'>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
import { ReactNode } from 'react'

import { Paper } from '@audius/harmony'
import cn from 'classnames'

import styles from '../OAuthLoginPage.module.css'
import { Display } from '../types'

export const ContentWrapper = ({ children }: { children: ReactNode }) => (
<div className={styles.wrapper}>
<div className={styles.container}>{children}</div>
export const ContentWrapper = ({
display,
children
}: {
display: Display
children: ReactNode
}) => (
<div className={cn(styles.wrapper, { [styles.popup]: display === 'popup' })}>
{display === 'popup' ? (
<div className={styles.container}>{children}</div>
) : (
<Paper
shadow='mid'
w='375px'
direction='column'
pv='3xl'
ph='xl'
mv='3xl'
alignSelf='flex-start'
borderRadius='xl'
>
{children}
</Paper>
)}
</div>
)
12 changes: 10 additions & 2 deletions packages/web/src/pages/oauth-login-page/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as errorActions from 'store/errors/actions'
import { reportToSentry } from 'store/errors/reportToSentry'

import { messages } from './messages'
import { Display } from './types'
import {
authWrite,
formOAuthResponse,
Expand Down Expand Up @@ -47,6 +48,7 @@ export const useParsedQueryParams = () => {
api_key: apiKey,
origin,
tx,
display: displayQueryParam,
...rest
} = queryString.parse(search)

Expand Down Expand Up @@ -130,6 +132,9 @@ export const useParsedQueryParams = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isRedirectValid, parsedOrigin, parsedRedirectUri, search])

const display: Display =
displayQueryParam === 'fullScreen' ? 'fullScreen' : 'popup'

return {
apiKey,
appName,
Expand All @@ -143,7 +148,8 @@ export const useParsedQueryParams = () => {
parsedOrigin,
error,
tx,
txParams
txParams,
display
}
}

Expand Down Expand Up @@ -181,6 +187,7 @@ export const useOAuthSetup = ({
parsedOrigin,
txParams,
tx,
display,
error: initError
} = useParsedQueryParams()
const accountIsLoading = useSelector((state: CommonState) => {
Expand Down Expand Up @@ -518,6 +525,7 @@ export const useOAuthSetup = ({
userEmail,
authorize,
tx,
txParams: txParams as WriteOnceParams
txParams: txParams as WriteOnceParams,
display
}
}
1 change: 1 addition & 0 deletions packages/web/src/pages/oauth-login-page/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Display = 'popup' | 'fullScreen'