Home Reference Source
import Auth from '~/models/Auth.js'
public class | source

Auth

Manages authorization use Auth.shared() to get global instance

Static Member Summary

Static Public Members
public static get

Returns global instance of Auth

Static Method Summary

Static Public Methods
public static

OAuth endpoint

Constructor Summary

Public Constructor
public

Don't use this. Use Auth.shared()

Member Summary

Public Members
public get

Determines if user is authorized at the moment of call.

public get

Gets the current user.

Method Summary

Public Methods
public

Authorizes for an OAuth site with auth config using CLIENT flow.

public

async ensureLoggedIn(reason: string): boolean

Ensures the user is logged in.

public

async loginJWT(authData: AuthJWTToken): Promise

Logs into a code-golf user using a JWT authorization key.

public

async logout()

Logs the given user out.

Static Public Members

public static get shared: Promise<Auth> source

Returns global instance of Auth

Static Public Methods

public static oauthEndpointForSite(site: string, options: Object): string source

OAuth endpoint

Params:

NameTypeAttributeDescription
site string

Site ID

options Object
options.clientOnly boolean
  • optional
  • default: false

A boolean specifying it to use client flow.

options.authConfig AuthConfig
  • optional
  • default: {}

authorization config

Return:

string

URL to put into link

Public Constructors

public constructor() source

Don't use this. Use Auth.shared()

Public Members

public get isAuthorized: Boolean source

Determines if user is authorized at the moment of call.

Return:

Boolean

this is sync

public get user: User source

Gets the current user.

Public Methods

public authorizeOAuth(site: string, options: Object): Promise<string> source

Authorizes for an OAuth site with auth config using CLIENT flow.

Params:

NameTypeAttributeDescription
site string

site ID

options Object
  • optional

Options for Auth.oauthEndpointForSite

Return:

Promise<string>

Resolves to auth key.

public async ensureLoggedIn(reason: string): boolean source

Ensures the user is logged in.

Params:

NameTypeAttributeDescription
reason string
  • nullable: true

Why this is being ensured.

Return:

boolean

false is user refused to login and is not logged in.

public async loginJWT(authData: AuthJWTToken): Promise source

Logs into a code-golf user using a JWT authorization key.

Params:

NameTypeAttributeDescription
authData AuthJWTToken

Authorization data

Return:

Promise

resolves to a User of the logged in user.

public async logout() source

Logs the given user out. You must reload the pages for changes.