Skip to content

Commit 280e453

Browse files
authored
docs(repo): enrich tsdoc with examples and notes (#2152)
1 parent ef32e04 commit 280e453

File tree

3 files changed

+1439
-25
lines changed

3 files changed

+1439
-25
lines changed

packages/core/auth-js/src/GoTrueClient.ts

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,173 @@ export default class GoTrueClient {
604604
*
605605
* @returns A logged-in session if the server has "autoconfirm" ON
606606
* @returns A user if the server has "autoconfirm" OFF
607+
*
608+
* @category Auth
609+
*
610+
* @remarks
611+
* - By default, the user needs to verify their email address before logging in. To turn this off, disable **Confirm email** in [your project](/dashboard/project/_/auth/providers).
612+
* - **Confirm email** determines if users need to confirm their email address after signing up.
613+
* - If **Confirm email** is enabled, a `user` is returned but `session` is null.
614+
* - If **Confirm email** is disabled, both a `user` and a `session` are returned.
615+
* - When the user confirms their email address, they are redirected to the [`SITE_URL`](/docs/guides/auth/redirect-urls#use-wildcards-in-redirect-urls) by default. You can modify your `SITE_URL` or add additional redirect URLs in [your project](/dashboard/project/_/auth/url-configuration).
616+
* - If signUp() is called for an existing confirmed user:
617+
* - When both **Confirm email** and **Confirm phone** (even when phone provider is disabled) are enabled in [your project](/dashboard/project/_/auth/providers), an obfuscated/fake user object is returned.
618+
* - When either **Confirm email** or **Confirm phone** (even when phone provider is disabled) is disabled, the error message, `User already registered` is returned.
619+
* - To fetch the currently logged-in user, refer to [`getUser()`](/docs/reference/javascript/auth-getuser).
620+
*
621+
* @example Sign up with an email and password
622+
* ```js
623+
* const { data, error } = await supabase.auth.signUp({
624+
* email: 'example@email.com',
625+
* password: 'example-password',
626+
* })
627+
* ```
628+
*
629+
* @exampleResponse Sign up with an email and password
630+
* ```json
631+
* // Some fields may be null if "confirm email" is enabled.
632+
* {
633+
* "data": {
634+
* "user": {
635+
* "id": "11111111-1111-1111-1111-111111111111",
636+
* "aud": "authenticated",
637+
* "role": "authenticated",
638+
* "email": "example@email.com",
639+
* "email_confirmed_at": "2024-01-01T00:00:00Z",
640+
* "phone": "",
641+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
642+
* "app_metadata": {
643+
* "provider": "email",
644+
* "providers": [
645+
* "email"
646+
* ]
647+
* },
648+
* "user_metadata": {},
649+
* "identities": [
650+
* {
651+
* "identity_id": "22222222-2222-2222-2222-222222222222",
652+
* "id": "11111111-1111-1111-1111-111111111111",
653+
* "user_id": "11111111-1111-1111-1111-111111111111",
654+
* "identity_data": {
655+
* "email": "example@email.com",
656+
* "email_verified": false,
657+
* "phone_verified": false,
658+
* "sub": "11111111-1111-1111-1111-111111111111"
659+
* },
660+
* "provider": "email",
661+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
662+
* "created_at": "2024-01-01T00:00:00Z",
663+
* "updated_at": "2024-01-01T00:00:00Z",
664+
* "email": "example@email.com"
665+
* }
666+
* ],
667+
* "created_at": "2024-01-01T00:00:00Z",
668+
* "updated_at": "2024-01-01T00:00:00Z"
669+
* },
670+
* "session": {
671+
* "access_token": "<ACCESS_TOKEN>",
672+
* "token_type": "bearer",
673+
* "expires_in": 3600,
674+
* "expires_at": 1700000000,
675+
* "refresh_token": "<REFRESH_TOKEN>",
676+
* "user": {
677+
* "id": "11111111-1111-1111-1111-111111111111",
678+
* "aud": "authenticated",
679+
* "role": "authenticated",
680+
* "email": "example@email.com",
681+
* "email_confirmed_at": "2024-01-01T00:00:00Z",
682+
* "phone": "",
683+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
684+
* "app_metadata": {
685+
* "provider": "email",
686+
* "providers": [
687+
* "email"
688+
* ]
689+
* },
690+
* "user_metadata": {},
691+
* "identities": [
692+
* {
693+
* "identity_id": "22222222-2222-2222-2222-222222222222",
694+
* "id": "11111111-1111-1111-1111-111111111111",
695+
* "user_id": "11111111-1111-1111-1111-111111111111",
696+
* "identity_data": {
697+
* "email": "example@email.com",
698+
* "email_verified": false,
699+
* "phone_verified": false,
700+
* "sub": "11111111-1111-1111-1111-111111111111"
701+
* },
702+
* "provider": "email",
703+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
704+
* "created_at": "2024-01-01T00:00:00Z",
705+
* "updated_at": "2024-01-01T00:00:00Z",
706+
* "email": "example@email.com"
707+
* }
708+
* ],
709+
* "created_at": "2024-01-01T00:00:00Z",
710+
* "updated_at": "2024-01-01T00:00:00Z"
711+
* }
712+
* }
713+
* },
714+
* "error": null
715+
* }
716+
* ```
717+
*
718+
* @example Sign up with a phone number and password (SMS)
719+
* ```js
720+
* const { data, error } = await supabase.auth.signUp({
721+
* phone: '123456789',
722+
* password: 'example-password',
723+
* options: {
724+
* channel: 'sms'
725+
* }
726+
* })
727+
* ```
728+
*
729+
* @exampleDescription Sign up with a phone number and password (whatsapp)
730+
* The user will be sent a WhatsApp message which contains a OTP. By default, a given user can only request a OTP once every 60 seconds. Note that a user will need to have a valid WhatsApp account that is linked to Twilio in order to use this feature.
731+
*
732+
* @example Sign up with a phone number and password (whatsapp)
733+
* ```js
734+
* const { data, error } = await supabase.auth.signUp({
735+
* phone: '123456789',
736+
* password: 'example-password',
737+
* options: {
738+
* channel: 'whatsapp'
739+
* }
740+
* })
741+
* ```
742+
*
743+
* @example Sign up with additional user metadata
744+
* ```js
745+
* const { data, error } = await supabase.auth.signUp(
746+
* {
747+
* email: 'example@email.com',
748+
* password: 'example-password',
749+
* options: {
750+
* data: {
751+
* first_name: 'John',
752+
* age: 27,
753+
* }
754+
* }
755+
* }
756+
* )
757+
* ```
758+
*
759+
* @exampleDescription Sign up with a redirect URL
760+
* - See [redirect URLs and wildcards](/docs/guides/auth/redirect-urls#use-wildcards-in-redirect-urls) to add additional redirect URLs to your project.
761+
*
762+
* @example Sign up with a redirect URL
763+
* ```js
764+
* const { data, error } = await supabase.auth.signUp(
765+
* {
766+
* email: 'example@email.com',
767+
* password: 'example-password',
768+
* options: {
769+
* emailRedirectTo: 'https://example.com/welcome'
770+
* }
771+
* }
772+
* )
773+
* ```
607774
*/
608775
async signUp(credentials: SignUpWithPasswordCredentials): Promise<AuthResponse> {
609776
try {

0 commit comments

Comments
 (0)