mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-03-02 10:00:54 +08:00
feat: pass invite token through signup flow
This commit is contained in:
@@ -15,7 +15,7 @@ export function discordAuthorize(state = '') {
|
||||
window.location.href = url
|
||||
}
|
||||
|
||||
export async function discordExchange(code, state, reason) {
|
||||
export async function discordExchange(code, inviteToken, reason) {
|
||||
try {
|
||||
const config = useRuntimeConfig()
|
||||
const API_BASE_URL = config.public.apiBaseUrl
|
||||
@@ -26,7 +26,7 @@ export async function discordExchange(code, state, reason) {
|
||||
code,
|
||||
redirectUri: `${window.location.origin}/discord-callback`,
|
||||
reason,
|
||||
state,
|
||||
inviteToken,
|
||||
}),
|
||||
})
|
||||
const data = await res.json()
|
||||
|
||||
@@ -15,7 +15,7 @@ export function githubAuthorize(state = '') {
|
||||
window.location.href = url
|
||||
}
|
||||
|
||||
export async function githubExchange(code, state, reason) {
|
||||
export async function githubExchange(code, inviteToken, reason) {
|
||||
try {
|
||||
const config = useRuntimeConfig()
|
||||
const API_BASE_URL = config.public.apiBaseUrl
|
||||
@@ -26,7 +26,7 @@ export async function githubExchange(code, state, reason) {
|
||||
code,
|
||||
redirectUri: `${window.location.origin}/github-callback`,
|
||||
reason,
|
||||
state,
|
||||
inviteToken,
|
||||
}),
|
||||
})
|
||||
const data = await res.json()
|
||||
|
||||
@@ -21,7 +21,7 @@ export async function googleGetIdToken() {
|
||||
})
|
||||
}
|
||||
|
||||
export function googleAuthorize() {
|
||||
export function googleAuthorize(state = '') {
|
||||
const config = useRuntimeConfig()
|
||||
const GOOGLE_CLIENT_ID = config.public.googleClientId
|
||||
const WEBSITE_BASE_URL = config.public.websiteBaseUrl
|
||||
@@ -31,18 +31,23 @@ export function googleAuthorize() {
|
||||
}
|
||||
const redirectUri = `${WEBSITE_BASE_URL}/google-callback`
|
||||
const nonce = Math.random().toString(36).substring(2)
|
||||
const url = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${GOOGLE_CLIENT_ID}&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=id_token&scope=openid%20email%20profile&nonce=${nonce}`
|
||||
const url = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${GOOGLE_CLIENT_ID}&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=id_token&scope=openid%20email%20profile&nonce=${nonce}&state=${state}`
|
||||
window.location.href = url
|
||||
}
|
||||
|
||||
export async function googleAuthWithToken(idToken, redirect_success, redirect_not_approved) {
|
||||
export async function googleAuthWithToken(
|
||||
idToken,
|
||||
inviteToken,
|
||||
redirect_success,
|
||||
redirect_not_approved,
|
||||
) {
|
||||
try {
|
||||
const config = useRuntimeConfig()
|
||||
const API_BASE_URL = config.public.apiBaseUrl
|
||||
const res = await fetch(`${API_BASE_URL}/api/auth/google`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ idToken }),
|
||||
body: JSON.stringify({ idToken, inviteToken }),
|
||||
})
|
||||
const data = await res.json()
|
||||
if (res.ok && data.token) {
|
||||
@@ -66,7 +71,7 @@ export async function googleAuthWithToken(idToken, redirect_success, redirect_no
|
||||
export async function googleSignIn(redirect_success, redirect_not_approved) {
|
||||
try {
|
||||
const token = await googleGetIdToken()
|
||||
await googleAuthWithToken(token, redirect_success, redirect_not_approved)
|
||||
await googleAuthWithToken(token, '', redirect_success, redirect_not_approved)
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ export async function twitterAuthorize(state = '') {
|
||||
window.location.href = url
|
||||
}
|
||||
|
||||
export async function twitterExchange(code, state, reason) {
|
||||
export async function twitterExchange(code, inviteToken, reason) {
|
||||
try {
|
||||
const config = useRuntimeConfig()
|
||||
const API_BASE_URL = config.public.apiBaseUrl
|
||||
@@ -55,7 +55,7 @@ export async function twitterExchange(code, state, reason) {
|
||||
code,
|
||||
redirectUri: `${window.location.origin}/twitter-callback`,
|
||||
reason,
|
||||
state,
|
||||
inviteToken,
|
||||
codeVerifier,
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user