@corbado/webcomponent
The @corbado/webcomponent
JavaScript library empowers developers to build seamless passkey-first authentication into
their applications. It facilitates user sign-up, login, and session management operations directly from your
JavaScript (Frontend).
Installation
You can install @corbado/webcomponent
either as an ES module via npm, or load it as a script in your HTML. Both
methods are discussed below.
Install as an ES module
Install the package with npm
npm install @corbado/webcomponent
After installing, import Corbado
into your JavaScript files and initialize it with your Frontend API
.
Install as a script
To load Corbado
directly in your HTML using a <script/>
tag, add the following script:
<script defer src="https://auth.corbado.com/auth.js"></script>
Usage
The usage of @corbado/webcomponent
differs slightly depending on your choice of JavaScript or a frontend framework.
Examples are provided below for vanilla JavaScript, React, and Vue.js.
Vanilla JS
Include corbado-auth-provider
and corbado-auth
tags in your HTML:
<body>
<corbado-auth-provider endpoint="<Frontend API>">
<corbado-auth endpoint="<Frontend API>" conditional="yes">
<input id="corbado-username" autocomplete="webauthn" name="username" required value=""/>
</corbado-auth>
</corbado-auth-provider>
</body>
React
Use @corbado/webcomponent
in your React components:
import Corbado from '@corbado/webcomponent';
import '@corbado/webcomponent/pkg/auth_cui.css';
const frontendAPI = 'https://<project ID>.auth.corbado.com';
const corbado = new Corbado.Session('<project ID>', frontendAPI);
function App() {
let [currentUser, setCurrentUser] = useState(null);
async function logout() {
await corbado.logout();
}
corbado.initialize(user => {
setCurrentUser(user)
});
return (
<corbado-auth endpoint={corbadoAuthenticationURL} conditional="yes">
<input id="corbado-username" autoComplete="webauthn" name="username" required value=""/>
</corbado-auth>
)
}
Vue.js
Use corbado-auth-provider
and corbado-auth
tags in your Vue templates:
<template>
<corbado-auth-provider endpoint="<Frontend API>">
<corbado-auth endpoint="<Frontend API>" conditional="yes">
<input id="corbado-username" autocomplete="webauthn" name="username" required value=""/>
</corbado-auth>
</corbado-auth-provider>
</template>
<script setup>
import "@corbado/webcomponent"
import "@corbado/webcomponent/pkg/auth_cui.css"
</script>
Vue.js 3 setup:
export default defineConfig(({command, mode, ssrBuild}) => {
console.log(command, mode, ssrBuild)
return {
build: {
sourcemap: command === 'build',
},
plugins: [
vue({
template: {
transformAssetUrls,
compilerOptions: {
isCustomElement: (tag) => tag.startsWith('corbado-')
},
},
}),
vuetify({
autoImport: true,
}),
],
define: {'process.env': {}},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
extensions: [
'.js',
'.json',
'.jsx',
'.mjs',
'.ts',
'.tsx',
'.vue',
],
},
server: {
port: 3000,
},
}
})
Vue.js 2 setup:
import {i18n} from '@/plugins/i18n'
import '@/plugins/vue-composition-api'
import '@/styles/styles.scss'
import Vue from 'vue'
import App from './App.vue'
import './plugins/acl'
import vuetify from './plugins/vuetify'
import router from './router'
import store from './store'
Vue.config.productionTip = false
Vue.config.ignoredElements = [
'corbado-auth',
]
new Vue({
router,
store,
i18n,
vuetify,
render: h => h(App),
}).$mount('#app')
Getting help
Have questions or need help? Here's how you can reach us:
Security
@corbado/webcomponent
follows good practices of security, but 100% security cannot be assured.
@corbado/webcomponent
is provided "as is" without any warranty. Use at your own risk.