Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add prettier with ionic config #137

Merged
merged 2 commits into from
Aug 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 41 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# CapacitorGoogleAuth

Capacitor plugin for Google Auth.

## Contributions

PRs are welcome and much appreciated that keeps this plugin up to date with Capacitor and official Google Auth platform library feature parity.

Try to follow good code practices. You can even help keeping the included demo updated.
Expand All @@ -10,11 +12,10 @@ PRs for features that are not aligned with the official Google Auth library are

(We are beginner-friendly here)



## Install

#### 1. Install package

```bash
npm i --save @codetrix-studio/capacitor-google-auth

Expand All @@ -23,40 +24,48 @@ npm i --save @codetrix-studio/capacitor-google-auth@2.1.3
```

#### 2. Update capacitor deps

```sh
npx cap update
```

#### 3. Migrate from 2 to 3 version

if your migrate from Capacitor 2 to Capacitor 3 [see instruction for migrate plugin to new version](#migrate-from-2-to-3)

## Usage

for capacitor 2.x.x use [instruction](https://github.com/CodetrixStudio/CapacitorGoogleAuth/blob/79129ab37288f5f5d0bb9a568a95890e852cebc2/README.md)

### WEB

Add [`clientId`](https://developers.google.com/identity/sign-in/web/sign-in#specify_your_apps_client_id) meta tag to head.

```html
<meta name="google-signin-client_id" content="{your client id here}">
<meta name="google-signin-client_id" content="{your client id here}" />
```

Register plugin and manually initialize

```ts
import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';

// use hook after platform dom ready
GoogleAuth.init()
GoogleAuth.init();
```


Use it

```ts
GoogleAuth.signIn()
GoogleAuth.signIn();
```

#### AngularFire2

init hook

```ts
// app.component.ts
// app.component.ts
constructor() {
this.initializeApp();
}
Expand All @@ -68,7 +77,8 @@ initializeApp() {
}
```

sign in function
sign in function

```ts
async googleSignIn() {
let googleUser = await GoogleAuth.signIn();
Expand All @@ -78,79 +88,86 @@ async googleSignIn() {
```

#### Vue 3

```ts
// App.vue
import { defineComponent, onMounted } from 'vue'
import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth'
import { defineComponent, onMounted } from 'vue';
import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';

export default defineComponent({
setup() {
onMounted(() => {
GoogleAuth.init()
})
GoogleAuth.init();
});

const logIn = async () => {
const response = await GoogleAuth.signIn()
console.log(response)
}
const response = await GoogleAuth.signIn();
console.log(response);
};

return {
logIn
}
}
})
logIn,
};
},
});
```

### iOS

Make sure you have `GoogleService-Info.plist` with `CLIENT_ID`

Add `REVERSED_CLIENT_ID` as url scheme to `Info.plist`

### Android

Inside your `strings.xml`

```xml
<resources>
<string name="server_client_id">Your Web Client Key</string>
</resources>
```

Import package inside your `MainActivity`

```java
import com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth;
```

Register plugin inside your `MainActivity.onCreate`

```java
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
add(GoogleAuth.class);
}});
```

## Configure

Provide configuration in root `capacitor.config.json`

```json
{
"plugins": {
"GoogleAuth": {
"scopes": ["profile", "email"],
"serverClientId": "xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
"forceCodeForRefreshToken" : true
"forceCodeForRefreshToken": true
}
}
}

```

Note : `forceCodeForRefreshToken` force user to select email address to regenerate AuthCode used to get a valid refreshtoken (work on iOS and Android) (This is used for offline access and serverside handling)


## Migration guide

#### Migrate from 2 to 3

After [migrate to Capcitor 3](https://capacitorjs.com/docs/updating/3-0) updating you projects, see diff:

##### WEB

```diff
- import "@codetrix-studio/capacitor-google-auth";
- import { Plugins } from '@capacitor/core';
Expand Down
40 changes: 38 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
"@capacitor/core": "^3.0.1",
"@capacitor/android": "^3.0.1",
"@capacitor/ios": "^3.0.1",
"@ionic/prettier-config": "^2.0.0",
"@types/gapi": "0.0.39",
"@types/gapi.auth2": "0.0.54",
"prettier": "^2.3.2",
"typescript": "^4.3.2"
},
"peerDependencies": {
Expand Down Expand Up @@ -56,5 +58,6 @@
},
"bugs": {
"url": "https://github.com/CodetrixStudio/CapacitorGoogleAuth.git/issues"
}
},
"prettier": "@ionic/prettier-config"
}
8 changes: 3 additions & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ export default {
file: 'dist/plugin.js',
format: 'iife',
name: 'capacitorPlugin',
sourcemap: true
sourcemap: true,
},
plugins: [
nodeResolve()
]
};
plugins: [nodeResolve()],
};
2 changes: 1 addition & 1 deletion src/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Authentication, User } from "./user";
import { Authentication, User } from './user';

export interface GoogleAuthPlugin {
signIn(): Promise<User>;
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { registerPlugin } from '@capacitor/core';
import type { GoogleAuthPlugin } from './definitions';

const GoogleAuth = registerPlugin<GoogleAuthPlugin>('GoogleAuth', {
web: () => import('./web').then(m => new m.GoogleAuthWeb()),
web: () => import('./web').then((m) => new m.GoogleAuthWeb()),
});

export * from './definitions';
Expand Down
24 changes: 12 additions & 12 deletions src/user.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export interface User {
id: string;
email: string;

name: string;
familyName: string;
givenName: string;
imageUrl: string;
id: string;
email: string;

serverAuthCode: string;
authentication: Authentication;
name: string;
familyName: string;
givenName: string;
imageUrl: string;

serverAuthCode: string;
authentication: Authentication;
}

export interface Authentication {
accessToken: string;
idToken: string;
}
accessToken: string;
idToken: string;
}
Loading