Skip to content

Commit 70b7a30

Browse files
Improve README file (#62)
1 parent a3c97f7 commit 70b7a30

File tree

1 file changed

+32
-35
lines changed

1 file changed

+32
-35
lines changed

README.md

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# supabase-swift
22

3-
Supabase client for swift. Mirrors the design of [supabase-js](https://github.com/supabase/supabase-js/blob/master/README.md)
3+
Supabase client for swift. Mirrors the design of [supabase-js](https://github.com/supabase/supabase-js/blob/master/README.md).
44

55
## Installation
66

@@ -27,28 +27,22 @@ If you're using Xcode, [use this guide](https://developer.apple.com/documentatio
2727

2828
## Usage
2929

30-
For all requests made for supabase, you will need to initialize a `SupabaseClient` object.
30+
To make requests to the `Supabase` database, you will need to initialize a `SupabaseClient` object:
3131

3232
```swift
3333
let client = SupabaseClient(supabaseURL: "{ Supabase URL }", supabaseKey: "{ Supabase anonymous Key }")
3434
```
3535

3636
## Login Implementation
3737

38-
Import and Initialize GoTrueSwift which is bundled with Supabase Swift
39-
```swift
40-
import GoTrue
41-
42-
//Intialize Gotrue
43-
var client: GoTrueClient = GoTrueClient(url: "{ Supabase URL }", headers: ["apikey": { Supabase anonymous Key }])
44-
```
38+
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.
4539

46-
Here's how to Sign Up with Email and get the signed in users Session Info.
40+
- Here's how to sign up with an email and password and get the signed in user `Session` info:
4741

4842
```swift
4943
Task {
5044
do {
51-
try await client.signUp(email: email, password: password)
45+
try await client.auth.signUp(email: email, password: password)
5246
let session = try await client.session
5347
print("### Session Info: \(session)")
5448
} catch {
@@ -57,12 +51,12 @@ Task {
5751
}
5852
```
5953

60-
Here's how to Login with Email for an existing users and get the logged in users Session Info.
54+
- For existing users, here's how to log in with an email and password and get the logged in user `Session` info:
6155

6256
```swift
6357
Task {
6458
do {
65-
try await client.signIn(email: email, password: password)
59+
try await client.auth.signIn(email: email, password: password)
6660
let session = try await client.session
6761
print("### Session Info: \(session)")
6862
} catch {
@@ -75,9 +69,10 @@ Task {
7569

7670
### Setup Callback URL
7771

78-
We need to first setup the callback URL for all Social Logins inside the app.
72+
We need to first set up the callback URL for all Social Logins inside the app.
73+
74+
- Setup the callback `URL` on `Info.plist`:
7975

80-
- Setup the callback URL on Info.plist
8176
```xml
8277
<array>
8378
<dict>
@@ -90,21 +85,23 @@ We need to first setup the callback URL for all Social Logins inside the app.
9085
</dict>
9186
</array>
9287
```
93-
- Add this callback URL on Supabase under Authentication -> URL Configuration -> Redirect URLs
88+
89+
- Add this callback `URL` on `Supabase` under `Authentication -> URL Configuration -> Redirect URLs`.
9490

9591
### Google Sign In
9692

97-
- Setup Google Auth as per [Supabase's Documentation](https://supabase.com/docs/guides/auth/social-login/auth-google)
98-
- Note: For iOS we still need to use Google Consent Form for Web
99-
- Import SafariServices to your ViewController and create a SafariVC instance
93+
- Setup Google Auth as per [Supabase's Documentation](https://supabase.com/docs/guides/auth/social-login/auth-google).
94+
- Note: For iOS we still need to use Google Consent Form for Web.
95+
- Import `SafariServices` in your `ViewController` and create a `SFSafariViewController` instance:
10096

10197
```swift
10298
import SafariServices
10399

104100
var safariVC: SFSafariViewController?
105101
```
106-
- Get the URL for Google Sign in from Supabase and load it on SFSafariViewController
107-
- Add the previous callback URL you set up in the redirecTo
102+
103+
- Get the `URL` for Google Sign in from `Supabase` and load it on `SFSafariViewController`.
104+
- Pass the previous callback `URL` you set up in the `redirecTo` parameter:
108105

109106
```swift
110107
Task {
@@ -117,8 +114,10 @@ Task {
117114
}
118115
}
119116
```
120-
- Handle the callback URL on SceneDelegate. (For older projects you can use AppDelegate if SceneDelegate is not there in the project)
121-
- 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
117+
118+
- Handle the callback `URL` on `SceneDelegate` (for older projects, you can use `AppDelegate` if `SceneDelegate` is not present).
119+
- 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.
120+
122121
```swift
123122
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
124123
if let url = URLContexts.first?.url as? URL {
@@ -129,7 +128,9 @@ func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>)
129128
}
130129
}
131130
```
132-
- In your View Controller observe for the Notification and handle minimizing the SFSafariViewController and get the session
131+
132+
- In your `ViewController`, observe for the `Notification` and handle it minimizing the `SFSafariViewController` and getting the session:
133+
133134
```swift
134135
NotificationCenter.default.addObserver(
135136
self,
@@ -153,9 +154,9 @@ NotificationCenter.default.addObserver(
153154

154155
### Apple Sign In
155156

156-
- Setup Apple Auth as per [Supabase's Documentation](https://supabase.com/docs/guides/auth/social-login/auth-apple)
157-
- For Sign in with Apple follow the above as per Google Sign In and just replace the provider
158-
- Once the user moves to the SFSafariViewController the Apple Native Popup will slide up to continue with Sign In.
157+
- Setup Apple Auth as per [Supabase's Documentation](https://supabase.com/docs/guides/auth/social-login/auth-apple).
158+
- For Sign in with Apple follow the above as per Google Sign In and just replace the provider.
159+
- Once the user moves to the `SFSafariViewController`, an Apple native pop-up will slide up to continue with the sign in.
159160

160161
```swift
161162
Task {
@@ -171,19 +172,15 @@ Task {
171172

172173
### Other Social Logins
173174

174-
- 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
175+
- 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.
175176

176177
## Basic CRUD Implementation
177178

178-
Import and Initialize the Supabase client
179-
180-
```swift
181-
let client = SupabaseClient(supabaseURL: "{ Supabase URL }", supabaseKey: "{ Supabase anonymous Key }")
182-
```
179+
First, import and initialize `SupabaseClient`, as explained in "Usage" section.
183180

184181
### Insert Data
185182

186-
Create a model which follows the data structure of your table.
183+
- Create a model which follows your table's data structure:
187184

188185
```swift
189186
struct InsertModel: Encodable {
@@ -212,7 +209,7 @@ Task {
212209

213210
### Select Data
214211

215-
Using the same model as before
212+
- Using the same model as before:
216213

217214
```swift
218215
let insertData = InsertModel(title: "Test", desc: "Test Desc")

0 commit comments

Comments
 (0)