Skip to main content Skills Marketplace 커뮤니티가 만든 AI 스킬을 발견하고 탐색하세요.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/TencentCloudBase/awesome-cloudbase-examples --skill auth-web-cloudbase명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
Zip 다운로드 다운로드 중... name auth-web-cloudbase description CloudBase Web Authentication Quick Guide - Provides concise and practical Web frontend authentication solutions with multiple login methods and complete user management. alwaysApply false
Overview
Prerequisites : CloudBase environment ID (env)
Prerequisites : CloudBase environment Region (region)
Core Capabilities
Use Case : Web frontend projects using @cloudbase/js-sdk@2.24.0+ for user authentication
Key Benefits : Compatible with supabase-js API, supports phone, email, anonymous, username/password, and third-party login methods
@cloudbase/js-sdk cdn source : https://static.cloudbase.net/cloudbase-js-sdk/latest/cloudbase.full.js
Prerequisites
Automatically use auth-tool-cloudbase to get publishable key and configure login methods.
If auth-tool-cloudbase failed, let user go to https://tcb.cloud.tencent.com/dev?envId={env}#/env/apikey to get publishable key and https://tcb.cloud.tencent.com/dev?envId={env}#/identity/login-manage to set up login methods
Quick Start
import cloudbase from '@cloudbase/js-sdk'
const app = cloudbase. ({
: ,
: ,
: ,
: { : },
})
auth = app.
---
##
** ( )**
- use turn on
init
env
`env`
region
`region`
accessKey
'publishable key'
auth
detectSessionInUrl
true
const
auth
``
Login
Methods
1.
Phone
OTP
Recommended
Automatically
`auth-tool-cloudbase`
`SMS Login`
``
`js
const { data, error } = await auth.signInWithOtp({ phone: '13800138000' })
const { data: loginData, error: loginError } = await data.verifyOtp({ token:'123456' })
Automatically use auth-tool-cloudbase turn on Email Login
const { data, error } = await auth.signInWithOtp ({ email : 'user@example.com' })
const { data : loginData, error : loginError } = await data.verifyOtp ({ token : '654321' })
const { data, error } = await auth.signInWithPassword ({ username : 'test_user' , password : 'pass123' })
const { data, error } = await auth.signInWithPassword ({ email : 'user@example.com' , password : 'pass123' })
const { data, error } = await auth.signInWithPassword ({ phone : '13800138000' , password : 'pass123' })
4. Registration (Smart: auto-login if exists)
Only support email and phone otp registration
Automatically use auth-tool-cloudbase turn on Email Login or SMS Login
const { data, error } = await auth.signUp ({ email : 'new@example.com' , nickname : 'User' })
const { data : loginData, error : loginError } = await data.verifyOtp ({ token : '123456' })
const { data, error } = await auth.signUp ({ phone : '13800138000' , nickname : 'User' })
const { data : loginData, error : loginError } = await data.verifyOtp ({ token : '123456' })
Automatically use auth-tool-cloudbase turn on Anonymous Login
const { data, error } = await auth.signInAnonymously ()
Automatically use auth-tool-cloudbase turn on Google Login or WeChat Login
const { data, error } = await auth.signInWithOAuth ({ provider : 'google' })
window .location .href = data.url
await auth.signInWithCustomTicket (async () => {
const res = await fetch ('/api/ticket' )
return (await res.json ()).ticket
})
const { data, error } = await auth.getSession ()
const { data : signUpData, error : signUpError} = await auth.signUp ({
phone : '13800000000' ,
anonymous_token : data.session .access_token ,
})
await signUpData.verifyOtp ({ token : '123456' })
User Management
const { data, error } = await auth.signOut ()
const { data, error } = await auth.getUser ()
console .log (data.user .email , data.user .phone , data.user .user_metadata ?.nickName )
const { data, error } = await auth.updateUser ({ nickname : 'New Name' , gender : 'MALE' , avatar_url : 'url' })
const { data, error } = await auth.updateUser ({ email : 'new@example.com' })
const { data, error } = await data.verifyOtp ({ email : "new@example.com" , token : "123456" });
const { data, error } = await auth.resetPasswordForOld ({ old_password : 'old' , new_password : 'new' })
const { data, error } = await auth.reauthenticate ()
const { data, error } = await data.updateUser ({ nonce : '123456' , password : 'new' })
const { data, error } = await auth.linkIdentity ({ provider : 'google' })
const { data, error } = await auth.getUserIdentities ()
const { data, error } = await auth.unlinkIdentity ({ provider : data.identities [0 ].id })
const { data, error } = await auth.deleteMe ({ password : 'current' })
const { data, error } = auth.onAuthStateChange ((event, session, info ) => {
})
const { data, error } = const { data, error } = await auth.getSession ()
fetch ('/api/protected' , { headers : { Authorization : `Bearer ${data.session?.access_token} ` } })
const { data, error } = await auth.refreshUser ()
User Type declare type User = {
id : any
aud : string
role : string []
email : any
email_confirmed_at : string
phone : any
phone_confirmed_at : string
confirmed_at : string
last_sign_in_at : string
app_metadata : {
provider : any
providers : any []
}
user_metadata : {
name : any
picture : any
username : any
gender : any
locale : any
uid : any
nickName : any
avatarUrl : any
location : any
hasPassword : any
}
identities : any
created_at : string
updated_at : string
is_anonymous : boolean
}
Complete Example class PhoneLoginPage {
async sendCode ( ) {
const phone = document .getElementById ('phone' ).value
if (!/^1[3-9]\d{9}$/ .test (phone)) return alert ('Invalid phone' )
const { data, error } = await auth.signInWithOtp ({ phone })
if (error) return alert ('Send failed: ' + error.message )
this .verifyFunction = data.verify
document .getElementById ('codeSection' ).style .display = 'block'
this .startCountdown (60 )
}
async verifyCode ( ) {
const code = document .getElementById ('code' ).value
if (!code) return alert ('Enter code' )
const { data, error } = await this .verifyFunction (code)
if (error) return alert ('Verification failed: ' + error.message )
console .log ('Login successful:' , data.user )
window .location .href = '/dashboard'
}
startCountdown (seconds ) {
let countdown = seconds
const btn = document .getElementById ('resendBtn' )
btn.disabled = true
const timer = setInterval (() => {
countdown--
btn.innerText = `Resend in ${countdown} s`
if (countdown <= 0 ) {
clearInterval (timer)
btn.disabled = false
btn.innerText = 'Resend'
}
}, 1000 )
}
}
WeChat Mini Program
const { data, error } = await auth.signInWithOpenId ()
const { data, error } = await auth.signInWithOpenId ({ useWxCloud : false })
const { data, error } = await auth.signInWithPhoneAuth ({ phoneCode : 'xxx' })