diff --git a/README.md b/README.md index a7b9ad59..aaed034a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # supabase-swift -Supabase client for swift. Mirrors the design of [supabase-js](https://github.com/supabase/supabase-js/blob/master/README.md) +Supabase client for swift. Mirrors the design of [supabase-js](https://github.com/supabase/supabase-js/blob/master/README.md). ## Installation @@ -27,7 +27,7 @@ If you're using Xcode, [use this guide](https://developer.apple.com/documentatio ## Usage -For all requests made for supabase, you will need to initialize a `SupabaseClient` object. +To make requests to the `Supabase` database, you will need to initialize a `SupabaseClient` object: ```swift let client = SupabaseClient(supabaseURL: "{ Supabase URL }", supabaseKey: "{ Supabase anonymous Key }") @@ -35,20 +35,14 @@ let client = SupabaseClient(supabaseURL: "{ Supabase URL }", supabaseKey: "{ Sup ## Login Implementation -Import and Initialize GoTrueSwift which is bundled with Supabase Swift -```swift -import GoTrue - -//Intialize Gotrue -var client: GoTrueClient = GoTrueClient(url: "{ Supabase URL }", headers: ["apikey": { Supabase anonymous Key }]) -``` +Inside the `SupabaseClient` instance created before, you can find an `auth` property of type `GoTrueClient`. You can use it to perform sign in and sign up requests. -Here's how to Sign Up with Email and get the signed in users Session Info. +- Here's how to sign up with an email and password and get the signed in user `Session` info: ```swift Task { do { - try await client.signUp(email: email, password: password) + try await client.auth.signUp(email: email, password: password) let session = try await client.session print("### Session Info: \(session)") } catch { @@ -57,12 +51,12 @@ Task { } ``` -Here's how to Login with Email for an existing users and get the logged in users Session Info. +- For existing users, here's how to log in with an email and password and get the logged in user `Session` info: ```swift Task { do { - try await client.signIn(email: email, password: password) + try await client.auth.signIn(email: email, password: password) let session = try await client.session print("### Session Info: \(session)") } catch { @@ -75,9 +69,10 @@ Task { ### Setup Callback URL -We need to first setup the callback URL for all Social Logins inside the app. +We need to first set up the callback URL for all Social Logins inside the app. + +- Setup the callback `URL` on `Info.plist`: -- Setup the callback URL on Info.plist ```xml @@ -90,21 +85,23 @@ We need to first setup the callback URL for all Social Logins inside the app. ``` -- Add this callback URL on Supabase under Authentication -> URL Configuration -> Redirect URLs + +- Add this callback `URL` on `Supabase` under `Authentication -> URL Configuration -> Redirect URLs`. ### Google Sign In -- Setup Google Auth as per [Supabase's Documentation](https://supabase.com/docs/guides/auth/social-login/auth-google) -- Note: For iOS we still need to use Google Consent Form for Web -- Import SafariServices to your ViewController and create a SafariVC instance +- Setup Google Auth as per [Supabase's Documentation](https://supabase.com/docs/guides/auth/social-login/auth-google). +- Note: For iOS we still need to use Google Consent Form for Web. +- Import `SafariServices` in your `ViewController` and create a `SFSafariViewController` instance: ```swift import SafariServices var safariVC: SFSafariViewController? ``` -- Get the URL for Google Sign in from Supabase and load it on SFSafariViewController -- Add the previous callback URL you set up in the redirecTo + +- Get the `URL` for Google Sign in from `Supabase` and load it on `SFSafariViewController`. +- Pass the previous callback `URL` you set up in the `redirecTo` parameter: ```swift Task { @@ -117,8 +114,10 @@ Task { } } ``` -- Handle the callback URL on SceneDelegate. (For older projects you can use AppDelegate if SceneDelegate is not there in the project) -- Post NotificationCenter call to let the View Controller know that callback has been received and pass the URL received. This URL will be used to get the session for the user + +- Handle the callback `URL` on `SceneDelegate` (for older projects, you can use `AppDelegate` if `SceneDelegate` is not present). +- Post a `NotificationCenter` call to let the `ViewController` know the callback has been fired and pass the `URL` received. This `URL` will be used to get the user session. + ```swift func scene(_ scene: UIScene, openURLContexts URLContexts: Set) { if let url = URLContexts.first?.url as? URL { @@ -129,7 +128,9 @@ func scene(_ scene: UIScene, openURLContexts URLContexts: Set) } } ``` -- In your View Controller observe for the Notification and handle minimizing the SFSafariViewController and get the session + +- In your `ViewController`, observe for the `Notification` and handle it minimizing the `SFSafariViewController` and getting the session: + ```swift NotificationCenter.default.addObserver( self, @@ -153,9 +154,9 @@ NotificationCenter.default.addObserver( ### Apple Sign In -- Setup Apple Auth as per [Supabase's Documentation](https://supabase.com/docs/guides/auth/social-login/auth-apple) -- For Sign in with Apple follow the above as per Google Sign In and just replace the provider -- Once the user moves to the SFSafariViewController the Apple Native Popup will slide up to continue with Sign In. +- Setup Apple Auth as per [Supabase's Documentation](https://supabase.com/docs/guides/auth/social-login/auth-apple). +- For Sign in with Apple follow the above as per Google Sign In and just replace the provider. +- Once the user moves to the `SFSafariViewController`, an Apple native pop-up will slide up to continue with the sign in. ```swift Task { @@ -171,19 +172,15 @@ Task { ### Other Social Logins -- Other Social Logins if using a webview will be similar to above and just follow the [Supabase's Documentation](https://supabase.com/docs/guides/auth/) for their setup +- If using a WebViews, other social logins will be similar to above. Just follow the [Supabase's Documentation](https://supabase.com/docs/guides/auth/) for their setup. ## Basic CRUD Implementation -Import and Initialize the Supabase client - -```swift -let client = SupabaseClient(supabaseURL: "{ Supabase URL }", supabaseKey: "{ Supabase anonymous Key }") -``` +First, import and initialize `SupabaseClient`, as explained in "Usage" section. ### Insert Data -Create a model which follows the data structure of your table. +- Create a model which follows your table's data structure: ```swift struct InsertModel: Encodable { @@ -212,7 +209,7 @@ Task { ### Select Data -Using the same model as before +- Using the same model as before: ```swift let insertData = InsertModel(title: "Test", desc: "Test Desc")