Complete reference for all methods available on StackClientApp and CurrentUser.
Authentication Methods
signInWithOAuth()
Initiate OAuth sign in with a provider.
await stackApp.signInWithOAuth('google');
OAuth provider ID: 'google', 'github', 'microsoft', 'facebook', etc.
URL to redirect to after authentication
Returns: Promise<void> (redirects to OAuth provider)
signInWithCredential()
Sign in with email and password.
const result = await stackApp.signInWithCredential({
email: '[email protected]',
password: 'password123',
});
if (result.status === 'ok') {
console.log('Signed in successfully!');
} else {
console.error('Error:', result.error.message);
}
Don’t automatically redirect after sign in
Returns: Promise<Result<void, Error>>
signUpWithCredential()
Create account with email and password.
const result = await stackApp.signUpWithCredential({
email: '[email protected]',
password: 'secure_password',
});
if (result.status === 'ok') {
console.log('Account created!');
}
Don’t automatically redirect after sign up
Custom URL for email verification callback
Returns: Promise<Result<void, Error>>
sendMagicLinkEmail()
Send a magic link to user’s email.
const result = await stackApp.sendMagicLinkEmail('[email protected]');
if (result.status === 'ok') {
console.log('Magic link sent!');
console.log('Nonce:', result.data.nonce);
}
Custom callback URL for the magic link
Returns: Promise<Result<{ nonce: string }, Error>>
signInWithMagicLink()
Sign in using a magic link code.
const code = new URLSearchParams(window.location.search).get('code');
const result = await stackApp.signInWithMagicLink(code);
if (result.status === 'ok') {
console.log('Signed in!');
}
Magic link verification code from URL
Don’t automatically redirect after sign in
Returns: Promise<Result<void, Error>>
signInWithPasskey()
Sign in using WebAuthn passkey.
const result = await stackApp.signInWithPasskey();
if (result.status === 'ok') {
console.log('Signed in with passkey!');
}
Returns: Promise<Result<void, Error>>
Password Management
sendForgotPasswordEmail()
Send password reset email.
const result = await stackApp.sendForgotPasswordEmail('[email protected]');
if (result.status === 'ok') {
console.log('Password reset email sent!');
}
Custom callback URL for password reset
Returns: Promise<Result<void, Error>>
resetPassword()
Reset password using verification code.
const code = new URLSearchParams(window.location.search).get('code');
const result = await stackApp.resetPassword({
code,
password: 'new_secure_password',
});
if (result.status === 'ok') {
console.log('Password reset successfully!');
}
Verification code from reset email
Returns: Promise<Result<void, Error>>
verifyPasswordResetCode()
Verify a password reset code is valid.
const code = new URLSearchParams(window.location.search).get('code');
const result = await stackApp.verifyPasswordResetCode(code);
if (result.status === 'ok') {
console.log('Code is valid!');
}
Verification code to validate
Returns: Promise<Result<void, Error>>
Email Verification
verifyEmail()
Verify email address using verification code.
const code = new URLSearchParams(window.location.search).get('code');
const result = await stackApp.verifyEmail(code);
if (result.status === 'ok') {
console.log('Email verified!');
}
Returns: Promise<Result<void, Error>>
User Methods
getUser()
Get the current authenticated user.
const user = await stackApp.getUser();
if (user) {
console.log('User:', user.displayName);
} else {
console.log('Not signed in');
}
or
'redirect' | 'throw' | 'anonymous'
Behavior when not authenticated:
'redirect': Redirect to sign in
'throw': Throw an error
'anonymous': Return anonymous user
Returns: Promise<CurrentUser | null>
getPartialUser()
Get partial user data from token only (faster, no API call).
const partialUser = await stackApp.getPartialUser({ from: 'token' });
if (partialUser) {
console.log('User ID:', partialUser.id);
}
from
'token' | 'convex'
default:"'token'"
Data source for user information
Returns: Promise<PartialUser | null>
Navigation Methods
redirectToSignIn()
Redirect to sign in page.
await stackApp.redirectToSignIn();
URL to return to after sign in
Returns: Promise<void>
redirectToSignUp()
Redirect to sign up page.
await stackApp.redirectToSignUp();
Returns: Promise<void>
redirectToAccountSettings()
Redirect to account settings.
await stackApp.redirectToAccountSettings();
Returns: Promise<void>
redirectToAfterSignIn()
Redirect to post-sign-in URL.
await stackApp.redirectToAfterSignIn();
Returns: Promise<void>
redirectToAfterSignUp()
Redirect to post-sign-up URL.
await stackApp.redirectToAfterSignUp();
Returns: Promise<void>
redirectToAfterSignOut()
Redirect to post-sign-out URL.
await stackApp.redirectToAfterSignOut();
Returns: Promise<void>
CurrentUser Methods
update()
Update user properties.
const user = await stackApp.getUser();
if (user) {
await user.update({
displayName: 'New Name',
profileImageUrl: 'https://example.com/avatar.jpg',
});
}
Returns: Promise<void>
signOut()
Sign out the current user.
const user = await stackApp.getUser();
if (user) {
await user.signOut();
}
Returns: Promise<void>
delete()
Delete the user account.
const user = await stackApp.getUser();
if (user) {
await user.delete();
}
Returns: Promise<void>
listTeams()
Get user’s teams.
const user = await stackApp.getUser();
if (user) {
const teams = await user.listTeams();
console.log('Teams:', teams);
}
Returns: Promise<Team[]>
getSelectedTeam()
Get currently selected team.
const user = await stackApp.getUser();
if (user) {
const team = user.getSelectedTeam();
console.log('Selected team:', team?.displayName);
}
Returns: Team | null
setSelectedTeam()
Set the selected team.
const user = await stackApp.getUser();
const teams = await user.listTeams();
if (teams.length > 0) {
await user.setSelectedTeam(teams[0]);
}
Returns: Promise<void>
hasPermission()
Check if user has a permission.
const user = await stackApp.getUser();
if (user) {
const isAdmin = await user.hasPermission('admin');
console.log('Is admin:', isAdmin);
}
Returns: Promise<boolean>
getConnectedAccounts()
Get connected OAuth accounts.
const user = await stackApp.getUser();
if (user) {
const accounts = await user.getConnectedAccounts();
console.log('Connected accounts:', accounts);
}
Returns: Promise<OAuthConnection[]>
Team Invitation Methods
verifyTeamInvitationCode()
Verify a team invitation code.
const code = new URLSearchParams(window.location.search).get('code');
const result = await stackApp.verifyTeamInvitationCode(code);
if (result.status === 'ok') {
console.log('Invitation is valid!');
}
Returns: Promise<Result<void, Error>>
acceptTeamInvitation()
Accept a team invitation.
const code = new URLSearchParams(window.location.search).get('code');
const result = await stackApp.acceptTeamInvitation(code);
if (result.status === 'ok') {
console.log('Joined team!');
}
Returns: Promise<Result<void, Error>>
getTeamInvitationDetails()
Get details about a team invitation.
const code = new URLSearchParams(window.location.search).get('code');
const result = await stackApp.getTeamInvitationDetails(code);
if (result.status === 'ok') {
console.log('Team:', result.data.teamDisplayName);
}
Returns: Promise<Result<{ teamDisplayName: string }, Error>>
Best Practices
Handle errors
Always check the status property of result objects.
Use async/await
All methods return promises - use async/await for cleaner code.
Check user existence
Always verify user is not null before calling user methods.
Store user state
Cache user data in your application state to avoid repeated API calls.