Skip to content

Commit

Permalink
feat: update alterDomain option(#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dongkyuuuu committed Aug 25, 2021
1 parent cadaa3e commit 1276745
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,19 @@ app
.use(VueRecaptcha, {
siteKey: "your recaptcha sitekey",
componentName: "your custom componet name", // default: 'vue-recaptcha'
alterDomain: false, // default: false
})
.mount("#app");
```

### \*install options

| Option | Type | Description |
| --------------- | --------- | ------------------------------------------------------------------------------------- |
| `siteKey` | `string` | (required) recaptcha siteKey |
| `componentName` | `string` | If you want to use custom component name, use this option. (default: `vue-recaptcha`) |
| `alterDomain` | `boolean` | `true`: domain replace `www.google.com` with `www.recaptch.net` |

### Composition API

```html
Expand Down
2 changes: 1 addition & 1 deletion playground/utils/recaptcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import VueRecaptcha from "../../dist/vue3-recaptcha-v2";
import siteKey from "../config";

export default function install(app: App<Element>) {
app.use(VueRecaptcha, { siteKey: siteKey });
app.use(VueRecaptcha, { siteKey: siteKey, alternativeDomain: true });
}
16 changes: 8 additions & 8 deletions src/config/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ import { state } from "./state";
const ERROR_MSG_SITEKEY = "options must be included siteKey";

export function install(app: App<Element>, options: options) {
const componentName = options.componentName
? options.componentName
: "vue-recaptcha";

if (!options.siteKey) throw new Error(ERROR_MSG_SITEKEY);
_script();
_script(options);

state.siteKey = options.siteKey;
app.component(componentName, VueRecaptcha);
app.component(
options.componentName ? options.componentName : "vue-recaptcha",
VueRecaptcha
);
}

function _script() {
function _script(options: options) {
const domain = options.alterDomain ? "www.recaptcha.net" : "www.google.com";
const isExist = document.getElementById("vue3-recaptcha-v2");
if (isExist) return;

const script = document.createElement("script");
script.setAttribute("id", "vue3-recaptcha-v2");
script.setAttribute(
"src",
"https://www.google.com/recaptcha/api.js?render=explicit"
`https://${domain}/recaptcha/api.js?render=explicit`
);
script.setAttribute("async", "");
script.setAttribute("defer", "");
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export interface options {
siteKey: string;
componentName?: string;
alterDomain?: boolean;
}

/**
Expand Down

0 comments on commit 1276745

Please sign in to comment.