Skip to content

Commit

Permalink
fix: move channel parameter from sign in to sign up (#647)
Browse files Browse the repository at this point in the history
The `channel` parameter for WhatsApp should be on the `Signup` method
instead of the `SignIn` method

Relevant Server side code:
https://github.com/supabase/gotrue/blob/master/internal/api/signup.go#L22

---------

Co-authored-by: joel@joellee.org <joel@joellee.org>
Co-authored-by: Stojan Dimitrovski <sdimitrovski@gmail.com>
  • Loading branch information
3 people committed Apr 6, 2023
1 parent 325d748 commit e83caba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
7 changes: 2 additions & 5 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ export default class GoTrueClient {
phone,
password,
data: options?.data ?? {},
channel: options?.channel ?? 'sms',
gotrue_meta_security: { captcha_token: options?.captchaToken },
},
xform: _sessionResponse,
Expand Down Expand Up @@ -325,10 +326,7 @@ export default class GoTrueClient {
* Be aware that you may get back an error message that will not distingish
* between the cases where the account does not exist or that the
* email/phone and password combination is wrong or that the account can only
* be accessed via social login. Do note that you will need
* to configure a Whatsapp sender on Twilio if you are using phone sign in
* with 'whatsapp'. The whatsapp channel is not supported on other providers
* at this time.
* be accessed via social login.
*/
async signInWithPassword(credentials: SignInWithPasswordCredentials): Promise<AuthResponse> {
try {
Expand All @@ -354,7 +352,6 @@ export default class GoTrueClient {
phone,
password,
gotrue_meta_security: { captcha_token: options?.captchaToken },
channel: options?.channel ?? 'sms',
},
xform: _sessionResponse,
})
Expand Down
8 changes: 6 additions & 2 deletions src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ export function generatePKCEVerifier() {
const verifierLength = 56
const array = new Uint32Array(verifierLength)
if (typeof window.crypto === 'undefined') {
throw new Error('PKCE is not supported on devices without WebCrypto API support or equivalent polyfills')
throw new Error(
'PKCE is not supported on devices without WebCrypto API support, please add polyfills'
)
}
window.crypto.getRandomValues(array)
return Array.from(array, dec2hex).join('')
Expand All @@ -255,7 +257,9 @@ async function sha256(randomString: string) {
const encoder = new TextEncoder()
const encodedData = encoder.encode(randomString)
if (typeof window.crypto === 'undefined') {
throw new Error('PKCE is not supported on devices without WebCrypto API support or equivalent polyfills')
throw new Error(
'PKCE is not supported on devices without WebCrypto API support, please add polyfills'
)
}
const hash = await window.crypto.subtle.digest('SHA-256', encodedData)
const bytes = new Uint8Array(hash)
Expand Down
6 changes: 3 additions & 3 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,10 @@ export type SignUpWithPasswordCredentials =
* The `data` should be a JSON object that includes user-specific info, such as their first and last name.
*/
data?: object
/** Verification token received when the user completes the captcha on the site. */
/** Verification token received when the user completes the captcha on the site. Requires a configured WhatsApp sender on Twilio */
captchaToken?: string
/** Messaging channel to use (e.g. whatsapp or sms) */
channel?: 'sms' | 'whatsapp'
}
}
export type SignInWithPasswordCredentials =
Expand Down Expand Up @@ -392,8 +394,6 @@ export type SignInWithPasswordCredentials =
data?: object
/** Verification token received when the user completes the captcha on the site. */
captchaToken?: string
/** Messaging channel to use (e.g. whatsapp or sms) */
channel?: 'sms' | 'whatsapp'
}
}

Expand Down

0 comments on commit e83caba

Please sign in to comment.