Example #1
0
        /// <summary>
        /// Signs a user up using an email address and password.
        /// </summary>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <param name="options">Optional Signup data.</param>
        /// <returns></returns>
        public async Task <Session> SignUpWithEmail(string email, string password, SignUpOptions options = null)
        {
            var body = new Dictionary <string, object> {
                { "email", email }, { "password", password }
            };

            if (options != null)
            {
                if (!string.IsNullOrEmpty(options.RedirectTo))
                {
                    body.Add("redirectTo", options.RedirectTo);
                }

                if (options.Data != null)
                {
                    body.Add("data", options.Data);
                }
            }

            var response = await Helpers.MakeRequest(HttpMethod.Post, $"{Url}/signup", body, Headers);

            // Gotrue returns a Session object for an auto-/pre-confirmed account
            var session = JsonConvert.DeserializeObject <Session>(response.Content);

            // If account is unconfirmed, Gotrue returned the user object, so fill User data
            // in from the parsed response.
            if (session.User == null)
            {
                // Gotrue returns a User object for an unconfirmed account
                session.User = JsonConvert.DeserializeObject <User>(response.Content);
            }

            return(session);
        }
Example #2
0
        /// <summary>
        /// Signs up a new user using their phone number and a password.The phone number of the user.
        /// </summary>
        /// <param name="phone">The phone number of the user.</param>
        /// <param name="password">The password of the user.</param>
        /// <param name="options">Optional Signup data.</param>
        /// <returns></returns>
        public Task <Session> SignUpWithPhone(string phone, string password, SignUpOptions options = null)
        {
            var body = new Dictionary <string, object> {
                { "phone", phone },
                { "password", password },
            };

            if (options != null)
            {
                if (!string.IsNullOrEmpty(options.RedirectTo))
                {
                    body.Add("redirectTo", options.RedirectTo);
                }

                if (options.Data != null)
                {
                    body.Add("data", options.Data);
                }
            }

            return(Helpers.MakeRequest <Session>(HttpMethod.Post, $"{Url}/signup", body, Headers));
        }
Example #3
0
        /// <summary>
        /// Signs up a user
        /// </summary>
        /// <param name="type">Type of signup</param>
        /// <param name="identifier">Phone or Email</param>
        /// <param name="password"></param>
        /// <param name="signUpOptions">Object containing redirectTo and optional user metadata (data)</param>
        /// <returns></returns>
        public static async Task <Session> SignUp(SignUpType type, string identifier, string password, StatelessClientOptions options, SignUpOptions signUpOptions = null)
        {
            try
            {
                var     api     = GetApi(options);
                Session session = null;
                switch (type)
                {
                case SignUpType.Email:
                    session = await api.SignUpWithEmail(identifier, password, signUpOptions);

                    break;

                case SignUpType.Phone:
                    session = await api.SignUpWithPhone(identifier, password, signUpOptions);

                    break;
                }

                if (session?.User?.ConfirmedAt != null)
                {
                    return(session);
                }

                return(null);
            }
            catch (RequestException ex)
            {
                throw ExceptionHandler.Parse(ex);
            }
        }
Example #4
0
 /// <summary>
 /// Signs up a user by email address
 /// </summary>
 /// <param name="email"></param>
 /// <param name="password"></param>
 /// <param name="signUpOptions">Object containing redirectTo and optional user metadata (data)</param>
 /// <returns></returns>
 public static Task <Session> SignUp(string email, string password, StatelessClientOptions options, SignUpOptions signUpOptions = null) => SignUp(SignUpType.Email, email, password, options, signUpOptions);
Example #5
0
        /// <summary>
        /// Signs up a user
        /// </summary>
        /// <param name="type"></param>
        /// <param name="identifier"></param>
        /// <param name="password"></param>
        /// <param name="options">Object containing redirectTo and optional user metadata (data)</param>
        /// <returns></returns>
        public async Task <Session> SignUp(SignUpType type, string identifier, string password, SignUpOptions options = null)
        {
            await DestroySession();

            try
            {
                Session session = null;
                switch (type)
                {
                case SignUpType.Email:
                    session = await api.SignUpWithEmail(identifier, password, options);

                    break;

                case SignUpType.Phone:
                    session = await api.SignUpWithPhone(identifier, password, options);

                    break;
                }

                if (session?.User?.ConfirmedAt != null)
                {
                    await PersistSession(session);

                    StateChanged?.Invoke(this, new ClientStateChanged(AuthState.SignedIn));

                    return(CurrentSession);
                }

                return(session);
            }
            catch (RequestException ex)
            {
                throw ExceptionHandler.Parse(ex);
            }
        }
Example #6
0
 /// <summary>
 /// Signs up a user by email address
 /// </summary>
 /// <param name="email"></param>
 /// <param name="password"></param>
 /// <param name="options">Object containing redirectTo and optional user metadata (data)</param>
 /// <returns></returns>
 public Task <Session> SignUp(string email, string password, SignUpOptions options = null) => SignUp(SignUpType.Email, email, password, options);