UNPKG

@lucasroll62/nuxt3-auth

Version:

An alternative module to @nuxtjs/auth

69 lines (68 loc) 1.7 kB
import { assignDefaults, addAuthorize, initializePasswordGrantFlow, assignAbsoluteEndpoints } from "../utils/provider"; function isPasswordGrant(strategy) { return strategy.grantType === "password"; } export function laravelPassport(nuxt, strategy) { const { url } = strategy; if (!url) { throw new Error("url is required is laravel passport!"); } const defaults = { name: "laravelPassport", token: { property: "access_token", type: "Bearer", name: "Authorization", maxAge: 60 * 60 * 24 * 365 }, refreshToken: { property: "refresh_token", data: "refresh_token", maxAge: 60 * 60 * 24 * 30 }, user: { property: false } }; let DEFAULTS; if (isPasswordGrant(strategy)) { DEFAULTS = { ...defaults, scheme: "refresh", endpoints: { token: url + "/oauth/token", login: { baseURL: "" }, refresh: { baseURL: "" }, logout: false, user: { url: url + "/api/auth/user" } }, grantType: "password" }; assignDefaults(strategy, DEFAULTS); assignAbsoluteEndpoints(strategy); initializePasswordGrantFlow(nuxt, strategy); } else { DEFAULTS = { ...defaults, scheme: "oauth2", endpoints: { authorization: url + "/oauth/authorize", token: url + "/oauth/token", userInfo: url + "/api/auth/user", logout: false }, responseType: "code", grantType: "authorization_code", scope: "*" }; assignDefaults(strategy, DEFAULTS); assignAbsoluteEndpoints(strategy); addAuthorize(nuxt, strategy); } }